steep 0.34.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ec77465913e4b2146e068c58f63b7ae8b5c51fd2391f6eb2776dba8372a81c2
4
- data.tar.gz: 7528dbaf4873d9eb77728521837ecb0fe43a2010036572be2c3dc017c5b903cc
3
+ metadata.gz: 5ddd53798b724f6fd1a93d869b03a3864db04bed448552a75dadeabe8d1bc51e
4
+ data.tar.gz: c85f6c58a010ed11dfc1041f8ba98007e0f557d7bda133222b94915dfed0d6ca
5
5
  SHA512:
6
- metadata.gz: b0426373f8fb9e48ccec48d0676d70d5a674a389a83624df78dc3deacaba23840b02cc94becba92304de35f98c8d8bb3af12ef185161e4e6a6c37600cb61a82d
7
- data.tar.gz: 5f3a32240541f116b6299c354fada0c8de398b6139b9d5e275e7b05490ccc401aa1b4f70978af5561e2ce9c6c7bb2587c1c8e43801276c0875000496ed332a5b
6
+ metadata.gz: 79a7742bdef0d368aa2dceaa528cf3e4bc74bccefafc0d6c366aa94994917e7d5560c8d4fd6f03adf0d50c3b8536d80d7e998bba3a9dc5cb872c7047c0079cba
7
+ data.tar.gz: 512b5bdf6efd6e465d5e3147de2df6cafb549fe68e05890efc13fffcc763b0cec1c48005a1734b6ade2cd120fa48059c435c20bad4b9998b1d15a0b4f557f615
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.35.0 (2020-11-14)
6
+
7
+ * Support third party RBS repository ([#231](https://github.com/soutaro/steep/pull/231), [#254](https://github.com/soutaro/steep/pull/254), [#255](https://github.com/soutaro/steep/pull/255))
8
+ * Boolean type semantics update ([#252](https://github.com/soutaro/steep/pull/252))
9
+ * More flexible record typing ([#256](https://github.com/soutaro/steep/pull/256))
10
+
5
11
  ## 0.34.0 (2020-10-27)
6
12
 
7
13
  * Add `steep stats` command to show method call typing stats ([#246](https://github.com/soutaro/steep/pull/246))
@@ -16,7 +16,7 @@ module Steep
16
16
  end
17
17
 
18
18
  def self.available_commands
19
- [:init, :check, :validate, :annotations, :version, :project, :watch, :langserver, :vendor, :stats]
19
+ [:init, :check, :validate, :annotations, :version, :project, :watch, :langserver, :stats]
20
20
  end
21
21
 
22
22
  def process_global_options
@@ -34,7 +34,7 @@ module Steep
34
34
 
35
35
  def setup_command
36
36
  @command = argv.shift&.to_sym
37
- if CLI.available_commands.include?(@command) || @command == :worker
37
+ if CLI.available_commands.include?(@command) || @command == :worker || @command == :vendor
38
38
  true
39
39
  else
40
40
  stderr.puts "Unknown command: #{command}"
@@ -47,6 +47,17 @@ module Steep
47
47
  target.options.libraries.each do |lib|
48
48
  stdout.puts " - #{lib}"
49
49
  end
50
+ stdout.puts " library dirs:"
51
+ Project::Target.construct_env_loader(options: target.options).tap do |loader|
52
+ loader.each_dir do |lib, path|
53
+ case lib
54
+ when :core
55
+ stdout.puts " - core: #{path}"
56
+ else
57
+ stdout.puts " - #{lib.name}: #{path}"
58
+ end
59
+ end
60
+ end
50
61
  end
51
62
 
52
63
  0
@@ -18,26 +18,7 @@ module Steep
18
18
  end
19
19
 
20
20
  def run
21
- stdout.puts "Vendoring into #{vendor_dir}..."
22
-
23
- vendorer = RBS::Vendorer.new(vendor_dir: vendor_dir)
24
-
25
- if clean_before
26
- stdout.puts " Cleaning directory..."
27
- vendorer.clean!
28
- end
29
-
30
- stdout.puts " Vendoring standard libraries..."
31
- vendorer.stdlib!
32
-
33
- if defined?(Bundler)
34
- Bundler.locked_gems.specs.each do |spec|
35
- if RBS::EnvironmentLoader.gem_sig_path(spec.name, spec.version.to_s).directory?
36
- stdout.puts " Vendoring rubygem: #{spec.full_name}..."
37
- vendorer.gem! spec.name, spec.version.to_s
38
- end
39
- end
40
- end
21
+ stdout.puts "`steep vendor` is deprecated. Use `rbs vendor` command directly"
41
22
 
42
23
  0
43
24
  end
@@ -7,12 +7,12 @@ module Steep
7
7
  attr_reader :libraries
8
8
  attr_reader :signatures
9
9
  attr_reader :ignored_sources
10
- attr_reader :no_builtin
11
10
  attr_reader :vendor_dir
12
11
  attr_reader :strictness_level
13
12
  attr_reader :typing_option_hash
13
+ attr_reader :repo_paths
14
14
 
15
- def initialize(name, sources: [], libraries: [], signatures: [], ignored_sources: [])
15
+ def initialize(name, sources: [], libraries: [], signatures: [], ignored_sources: [], repo_paths: [])
16
16
  @name = name
17
17
  @sources = sources
18
18
  @libraries = libraries
@@ -21,6 +21,7 @@ module Steep
21
21
  @vendor_dir = nil
22
22
  @strictness_level = :default
23
23
  @typing_option_hash = {}
24
+ @repo_paths = []
24
25
  end
25
26
 
26
27
  def initialize_copy(other)
@@ -32,6 +33,7 @@ module Steep
32
33
  @vendor_dir = other.vendor_dir
33
34
  @strictness_level = other.strictness_level
34
35
  @typing_option_hash = other.typing_option_hash
36
+ @repo_paths = other.repo_paths.dup
35
37
  end
36
38
 
37
39
  def check(*args)
@@ -71,13 +73,14 @@ module Steep
71
73
 
72
74
  def vendor(dir = "vendor/sigs", stdlib: nil, gems: nil)
73
75
  if stdlib || gems
74
- @vendor_dir = [
75
- stdlib&.yield_self {|x| Pathname(x) },
76
- gems&.yield_self {|x| Pathname(x) }
77
- ]
78
- else
79
- @vendor_dir = Pathname(dir)
76
+ Steep.logger.warn { "#vendor with stdlib: or gems: keyword is deprecated." }
80
77
  end
78
+
79
+ @vendor_dir = Pathname(dir)
80
+ end
81
+
82
+ def repo_path(*paths)
83
+ @repo_paths.push(*paths.map {|s| Pathname(s) })
81
84
  end
82
85
  end
83
86
 
@@ -124,6 +127,8 @@ module Steep
124
127
  signature_patterns: target.signatures,
125
128
  options: Options.new.tap do |options|
126
129
  options.libraries.push(*target.libraries)
130
+ options.repository_paths.push(*target.repo_paths)
131
+ options.vendor_path = target.vendor_dir
127
132
 
128
133
  case target.strictness_level
129
134
  when :strict
@@ -133,15 +138,6 @@ module Steep
133
138
  end
134
139
 
135
140
  options.merge!(target.typing_option_hash)
136
-
137
- case target.vendor_dir
138
- when Array
139
- options.vendored_stdlib_path = target.vendor_dir[0]
140
- options.vendored_gems_path = target.vendor_dir[1]
141
- when Pathname
142
- options.vendored_stdlib_path = target.vendor_dir + "stdlib"
143
- options.vendored_gems_path = target.vendor_dir + "gems"
144
- end
145
141
  end
146
142
  ).tap do |target|
147
143
  project.targets << target
@@ -5,16 +5,16 @@ module Steep
5
5
  attr_accessor :allow_missing_definitions
6
6
  attr_accessor :allow_unknown_constant_assignment
7
7
  attr_accessor :allow_unknown_method_calls
8
- attr_accessor :vendored_stdlib_path
9
- attr_accessor :vendored_gems_path
8
+ attr_accessor :vendor_path
10
9
  attr_reader :libraries
10
+ attr_reader :repository_paths
11
11
 
12
12
  def initialize
13
13
  apply_default_typing_options!
14
- self.vendored_gems_path = nil
15
- self.vendored_stdlib_path = nil
14
+ self.vendor_path = nil
16
15
 
17
16
  @libraries = []
17
+ @repository_paths = []
18
18
  end
19
19
 
20
20
  def apply_default_typing_options!
@@ -114,18 +114,27 @@ module Steep
114
114
  end
115
115
  end
116
116
 
117
- def environment
118
- @environment ||= RBS::Environment.new().yield_self do |env|
119
- stdlib_root = options.vendored_stdlib_path || RBS::EnvironmentLoader::STDLIB_ROOT
120
- gem_vendor_path = options.vendored_gems_path
121
- loader = RBS::EnvironmentLoader.new(stdlib_root: stdlib_root, gem_vendor_path: gem_vendor_path)
122
- options.libraries.each do |lib|
123
- loader.add(library: lib)
124
- end
125
- loader.load(env: env)
117
+ def self.construct_env_loader(options:)
118
+ repo = RBS::Repository.new(no_stdlib: options.vendor_path)
119
+ options.repository_paths.each do |path|
120
+ repo.add(path)
121
+ end
126
122
 
127
- env.resolve_type_names
123
+ loader = RBS::EnvironmentLoader.new(
124
+ core_root: options.vendor_path ? nil : RBS::EnvironmentLoader::DEFAULT_CORE_ROOT,
125
+ repository: repo
126
+ )
127
+ loader.add(path: options.vendor_path) if options.vendor_path
128
+ options.libraries.each do |lib|
129
+ name, version = lib.split(/:/, 2)
130
+ loader.add(library: name, version: version)
128
131
  end
132
+
133
+ loader
134
+ end
135
+
136
+ def environment
137
+ @environment ||= RBS::Environment.from_loader(Target.construct_env_loader(options: options))
129
138
  end
130
139
 
131
140
  def load_signatures(validate:)
@@ -147,7 +147,23 @@ module Steep
147
147
  success(constraints: constraints)
148
148
 
149
149
  when relation.super_type.is_a?(AST::Types::Boolean)
150
- success(constraints: constraints)
150
+ check(
151
+ Relation.new(sub_type: relation.sub_type, super_type: AST::Types::Union.build(types: [AST::Builtin.true_type, AST::Builtin.false_type])),
152
+ self_type: self_type,
153
+ assumption: assumption,
154
+ trace: trace,
155
+ constraints: constraints
156
+ )
157
+
158
+ when relation.sub_type.is_a?(AST::Types::Boolean)
159
+ check(
160
+ Relation.new(sub_type: AST::Types::Union.build(types: [AST::Builtin.true_type, AST::Builtin.false_type]),
161
+ super_type: relation.super_type),
162
+ self_type: self_type,
163
+ assumption: assumption,
164
+ trace: trace,
165
+ constraints: constraints
166
+ )
151
167
 
152
168
  when relation.sub_type.is_a?(AST::Types::Self) && !self_type.is_a?(AST::Types::Self)
153
169
  check(
@@ -326,23 +342,21 @@ module Steep
326
342
  constraints: constraints)
327
343
 
328
344
  when relation.sub_type.is_a?(AST::Types::Record) && relation.super_type.is_a?(AST::Types::Record)
329
- if Set.new(relation.sub_type.elements.keys).superset?(Set.new(relation.super_type.elements.keys))
330
- keys = relation.super_type.elements.keys
331
- type_pairs = keys.map {|key| [relation.sub_type.elements[key], relation.super_type.elements[key]] }
332
- results = type_pairs.flat_map do |t1, t2|
333
- relation = Relation.new(sub_type: t1, super_type: t2)
334
- [check(relation, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints),
335
- check(relation.flip, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)]
336
- end
345
+ keys = relation.super_type.elements.keys
346
+ relations = keys.map {|key|
347
+ Relation.new(
348
+ sub_type: relation.sub_type.elements[key] || AST::Builtin.nil_type,
349
+ super_type: relation.super_type.elements[key]
350
+ )
351
+ }
352
+ results = relations.map do |relation|
353
+ check(relation, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
354
+ end
337
355
 
338
- if results.all?(&:success?)
339
- success(constraints: constraints)
340
- else
341
- results.find(&:failure?)
342
- end
356
+ if results.all?(&:success?)
357
+ success(constraints: constraints)
343
358
  else
344
- failure(error: Result::Failure::UnknownPairError.new(relation: relation),
345
- trace: trace)
359
+ results.find(&:failure?)
346
360
  end
347
361
 
348
362
  when relation.sub_type.is_a?(AST::Types::Record) && relation.super_type.is_a?(AST::Types::Name::Base)
@@ -2423,7 +2423,10 @@ module Steep
2423
2423
  errors: [error]
2424
2424
  )
2425
2425
 
2426
- constr = synthesize_children(node, skips: [receiver])
2426
+ skips = [receiver]
2427
+ skips << node.children[0] if node.type == :block
2428
+
2429
+ constr = synthesize_children(node, skips: skips)
2427
2430
  if block_params
2428
2431
  block_annotations = source.annotations(block: node, factory: checker.factory, current_module: current_namespace)
2429
2432
 
@@ -2433,7 +2436,7 @@ module Steep
2433
2436
  block_annotations: block_annotations,
2434
2437
  block_body: block_body
2435
2438
  ) do |error|
2436
- errors << error
2439
+ constr.typing.add_error(error)
2437
2440
  end
2438
2441
  end
2439
2442
  end
@@ -3224,8 +3227,10 @@ module Steep
3224
3227
  end
3225
3228
  end
3226
3229
  expected_module_method_names = (module_context.module_definition&.methods || {}).each.with_object(Set[]) do |(name, method), set|
3227
- if method.implemented_in == module_context.module_definition.type_name
3228
- set << name
3230
+ if name != :new
3231
+ if method.implemented_in == module_context.module_definition.type_name
3232
+ set << name
3233
+ end
3229
3234
  end
3230
3235
  end
3231
3236
 
@@ -3486,6 +3491,8 @@ module Steep
3486
3491
  end
3487
3492
 
3488
3493
  def try_hash_type(node, hint)
3494
+ hint = expand_alias(hint)
3495
+
3489
3496
  case hint
3490
3497
  when AST::Types::Record
3491
3498
  typing.new_child(node.loc.expression.yield_self {|l| l.begin_pos..l.end_pos }) do |child_typing|
@@ -1,3 +1,3 @@
1
1
  module Steep
2
- VERSION = "0.34.0"
2
+ VERSION = "0.35.0"
3
3
  end
@@ -34,5 +34,5 @@ Gem::Specification.new do |spec|
34
34
  spec.add_runtime_dependency "rainbow", ">= 2.2.2", "< 4.0"
35
35
  spec.add_runtime_dependency "listen", "~> 3.0"
36
36
  spec.add_runtime_dependency "language_server-protocol", "~> 3.15.0.1"
37
- spec.add_runtime_dependency "rbs", "~> 0.14.0"
37
+ spec.add_runtime_dependency "rbs", "~> 0.17.0"
38
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.34.0
4
+ version: 0.35.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-27 00:00:00.000000000 Z
11
+ date: 2020-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -106,14 +106,14 @@ dependencies:
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: 0.14.0
109
+ version: 0.17.0
110
110
  type: :runtime
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
- version: 0.14.0
116
+ version: 0.17.0
117
117
  description: Gradual Typing for Ruby
118
118
  email:
119
119
  - matsumoto@soutaro.com