sorbet-runtime 0.6.12652 → 0.6.12730

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: 3b5ae526c822c1b9eac7f55430c678b64b807489cf4326c51c3a31f48ca4a8c0
4
- data.tar.gz: 901ac0445af6e20b17df21d2366ed09da7abaf54cbefe728ffd005fd553c1daf
3
+ metadata.gz: d7a9be1c70e2968dd0cf8382b60a6240101bdd6dda73fa9cc6d7ff4f24c09c01
4
+ data.tar.gz: fca2152b203801b6fd5a161b28c6ddf927cafe3f58773089b5611a8a6ca51a46
5
5
  SHA512:
6
- metadata.gz: 79f837c6cf32a3737045ad77d12945f8b8c79a46431c211b5014b2e425980249f2b118362e78e89239706e1456ad3a045910611fb152f48ed714a5626f6a458b
7
- data.tar.gz: b9cd8500296a6aad4250d6df216fa32e4007cf282a6273ac2247b8102b44f0f71bb7908e0c0a2e0aeccd0643b881fac95dd540c5ac6e3d61420ade1483972966
6
+ metadata.gz: 6923d78865db170b6444dd65cb9186abda836bd13f0f7ca5543cb81462b4ef32579525b936e9fd6913ce04e9b7055436ab679562a096e422b0ed74b653c48285
7
+ data.tar.gz: 92362c83b98f32ee55409adcf713a34c3b5f45203ba637c593335044c2a5fd16491d5e2ed84a2c593999afbda6e5984359e9293db90d76172403cf88dc8c8352
@@ -85,6 +85,7 @@ require_relative 'types/boolean'
85
85
 
86
86
  # Depends on types/utils
87
87
  require_relative 'types/types/typed_array'
88
+ require_relative 'types/types/typed_module'
88
89
  require_relative 'types/types/typed_class'
89
90
 
90
91
  # Props dependencies
@@ -114,6 +115,5 @@ require_relative 'types/props/private/parser'
114
115
  require_relative 'types/props/generated_code_validation'
115
116
 
116
117
  require_relative 'types/struct'
117
- require_relative 'types/non_forcing_constants'
118
118
 
119
119
  require_relative 'types/compatibility_patches'
data/lib/types/_types.rb CHANGED
@@ -367,4 +367,16 @@ module T
367
367
  end
368
368
  end
369
369
  end
370
+
371
+ module Module
372
+ def self.[](type)
373
+ if type.is_a?(T::Types::Untyped)
374
+ T::Types::TypedModule::Untyped::Private::INSTANCE
375
+ elsif type.is_a?(T::Types::Anything)
376
+ T::Types::TypedModule::Anything::Private::INSTANCE
377
+ else
378
+ T::Types::TypedModule::Private::Pool.type_for_module(type)
379
+ end
380
+ end
381
+ end
370
382
  end
@@ -2,9 +2,6 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module T::Configuration
5
- # Cache this comparisonn to avoid two allocations all over the place.
6
- AT_LEAST_RUBY_2_7 = Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7')
7
-
8
5
  # Announces to Sorbet that we are currently in a test environment, so it
9
6
  # should treat any sigs which are marked `.checked(:tests)` as if they were
10
7
  # just a normal sig.
@@ -448,11 +445,7 @@ module T::Configuration
448
445
  MODULE_NAME = Module.instance_method(:name)
449
446
  private_constant :MODULE_NAME
450
447
 
451
- @default_module_name_mangler = if T::Configuration::AT_LEAST_RUBY_2_7
452
- ->(type) { MODULE_NAME.bind_call(type) }
453
- else
454
- ->(type) { MODULE_NAME.bind(type).call } # rubocop:disable Performance/BindCall
455
- end
448
+ @default_module_name_mangler = ->(type) { MODULE_NAME.bind_call(type) }
456
449
 
457
450
  @module_name_mangler = nil
458
451
 
@@ -257,10 +257,8 @@ module T::Private::Methods
257
257
  # make sure to keep changes in sync.
258
258
  elsif method_sig.check_level == :always || (method_sig.check_level == :tests && T::Private::RuntimeLevels.check_tests?)
259
259
  CallValidation.validate_call(self, original_method, method_sig, args, blk)
260
- elsif T::Configuration::AT_LEAST_RUBY_2_7
261
- original_method.bind_call(self, *args, &blk)
262
260
  else
263
- original_method.bind(self).call(*args, &blk) # rubocop:disable Performance/BindCall
261
+ original_method.bind_call(self, *args, &blk)
264
262
  end
265
263
  end
266
264
  end
@@ -530,27 +528,15 @@ module T::Private::Methods
530
528
  @old_hooks = nil
531
529
  else
532
530
  old_included = T::Private::ClassUtils.replace_method(Module, :included, true) do |arg|
533
- if T::Configuration::AT_LEAST_RUBY_2_7
534
- old_included.bind_call(self, arg)
535
- else
536
- old_included.bind(self).call(arg) # rubocop:disable Performance/BindCall
537
- end
531
+ old_included.bind_call(self, arg)
538
532
  ::T::Private::Methods._hook_impl(arg, false, self)
539
533
  end
540
534
  old_extended = T::Private::ClassUtils.replace_method(Module, :extended, true) do |arg|
541
- if T::Configuration::AT_LEAST_RUBY_2_7
542
- old_extended.bind_call(self, arg)
543
- else
544
- old_extended.bind(self).call(arg) # rubocop:disable Performance/BindCall
545
- end
535
+ old_extended.bind_call(self, arg)
546
536
  ::T::Private::Methods._hook_impl(arg, true, self)
547
537
  end
548
538
  old_inherited = T::Private::ClassUtils.replace_method(Class, :inherited, true) do |arg|
549
- if T::Configuration::AT_LEAST_RUBY_2_7
550
- old_inherited.bind_call(self, arg)
551
- else
552
- old_inherited.bind(self).call(arg) # rubocop:disable Performance/BindCall
553
- end
539
+ old_inherited.bind_call(self, arg)
554
540
  ::T::Private::Methods._hook_impl(arg, false, self)
555
541
  end
556
542
  @old_hooks = [old_included, old_extended, old_inherited]
@@ -79,13 +79,13 @@ module T::Private::Methods::CallValidation
79
79
 
80
80
  # All the types for which valid? unconditionally returns `true`
81
81
  return_is_ignorable =
82
- (method_sig.return_type.equal?(T::Types::Untyped::Private::INSTANCE) ||
83
- method_sig.return_type.equal?(T::Types::Anything::Private::INSTANCE) ||
84
- method_sig.return_type.equal?(T::Types::AttachedClassType::Private::INSTANCE) ||
85
- method_sig.return_type.equal?(T::Types::SelfType::Private::INSTANCE) ||
86
- method_sig.return_type.is_a?(T::Types::TypeParameter) ||
87
- method_sig.return_type.is_a?(T::Types::TypeVariable) ||
88
- (method_sig.return_type.is_a?(T::Types::Simple) && method_sig.return_type.raw_type.equal?(BasicObject)))
82
+ method_sig.return_type.equal?(T::Types::Untyped::Private::INSTANCE) ||
83
+ method_sig.return_type.equal?(T::Types::Anything::Private::INSTANCE) ||
84
+ method_sig.return_type.equal?(T::Types::AttachedClassType::Private::INSTANCE) ||
85
+ method_sig.return_type.equal?(T::Types::SelfType::Private::INSTANCE) ||
86
+ method_sig.return_type.is_a?(T::Types::TypeParameter) ||
87
+ method_sig.return_type.is_a?(T::Types::TypeVariable) ||
88
+ (method_sig.return_type.is_a?(T::Types::Simple) && method_sig.return_type.raw_type.equal?(BasicObject))
89
89
 
90
90
  returns_anything_method = all_args_are_simple && return_is_ignorable
91
91
 
@@ -176,7 +176,7 @@ module T::Private::Methods::CallValidation
176
176
  # this code is sig validation code.
177
177
  # Please issue `finish` to step out of it
178
178
 
179
- return_value = T::Configuration::AT_LEAST_RUBY_2_7 ? original_method.bind_call(instance, *args, &blk) : original_method.bind(instance).call(*args, &blk)
179
+ return_value = original_method.bind_call(instance, *args, &blk)
180
180
 
181
181
  # The only type that is allowed to change the return value is `.void`.
182
182
  # It ignores what you returned and changes it to be a private singleton.
@@ -279,7 +279,7 @@ module T::Private::Methods::CallValidation
279
279
  # this code is sig validation code.
280
280
  # Please issue `finish` to step out of it
281
281
 
282
- return_value = T::Configuration::AT_LEAST_RUBY_2_7 ? original_method.bind_call(instance, *args, &blk) : original_method.bind(instance).call(*args, &blk)
282
+ return_value = original_method.bind_call(instance, *args, &blk)
283
283
 
284
284
  # The only type that is allowed to change the return value is `.void`.
285
285
  # It ignores what you returned and changes it to be a private singleton.
@@ -332,8 +332,4 @@ module T::Private::Methods::CallValidation
332
332
  end
333
333
  end
334
334
 
335
- if T::Configuration::AT_LEAST_RUBY_2_7
336
- require_relative './call_validation_2_7'
337
- else
338
- require_relative './call_validation_2_6'
339
- end
335
+ require_relative './call_validation_2_7'
@@ -264,9 +264,9 @@ class T::Props::Decorator
264
264
  nil
265
265
  end
266
266
 
267
- SAFE_NAME = T.let(/\A[A-Za-z_][A-Za-z0-9_-]*\z/.freeze, Regexp, checked: false)
267
+ SAFE_NAME = T.let(/\A[A-Za-z_][A-Za-z0-9_-]*\z/, Regexp, checked: false)
268
268
  # Should be exactly the same as `SAFE_NAME`, but with a leading `@`.
269
- SAFE_ACCESSOR_KEY_NAME = T.let(/\A@[A-Za-z_][A-Za-z0-9_-]*\z/.freeze, Regexp, checked: false)
269
+ SAFE_ACCESSOR_KEY_NAME = T.let(/\A@[A-Za-z_][A-Za-z0-9_-]*\z/, Regexp, checked: false)
270
270
 
271
271
  # Used to validate both prop names and serialized forms
272
272
  sig { params(name: T.any(Symbol, String)).void.checked(:never) }
@@ -327,9 +327,9 @@ class T::Props::Decorator
327
327
  sig(:final) { params(name: Symbol).returns(T::Boolean).checked(:never) }
328
328
  private def method_defined_on_ancestor?(name)
329
329
  (@class.method_defined?(name) || @class.private_method_defined?(name)) &&
330
- # Unfortunately, older versions of ruby don't allow the second parameter on
331
- # `private_method_defined?`.
332
- (!@class.method_defined?(name, false) && !@class.private_method_defined?(name, false))
330
+ # Unfortunately, older versions of ruby don't allow the second parameter on
331
+ # `private_method_defined?`.
332
+ !@class.method_defined?(name, false) && !@class.private_method_defined?(name, false)
333
333
  end
334
334
 
335
335
  sig(:final) { params(name: Symbol, rules: Rules).void.checked(:never) }
@@ -31,7 +31,7 @@ module T::Types
31
31
  @type.is_a?(other.type.singleton_class)
32
32
  when Simple
33
33
  @type.is_a?(other.raw_type)
34
- when TypedClass
34
+ when TypedClass, TypedModule
35
35
  @type.is_a?(other.underlying_class)
36
36
  else
37
37
  false
@@ -41,7 +41,7 @@ module T::Types
41
41
  case other
42
42
  when Simple
43
43
  @raw_type <= other.raw_type
44
- when TypedClass
44
+ when TypedClass, TypedModule
45
45
  # This case is a bit odd--we would have liked to solve this like we do
46
46
  # for `T::Array` et al., but don't for backwards compatibility.
47
47
  # See `type_for_module` below.
@@ -103,9 +103,9 @@ module T::Types
103
103
  elsif !Object.autoload?(:Set) && Object.const_defined?(:Set) && mod == ::Set
104
104
  T::Set[T.untyped]
105
105
  else
106
- # ideally we would have a case mapping from ::Class -> T::Class here
107
- # but for backwards compatibility we don't have that, and instead
108
- # have a special case in subtype_of_single?
106
+ # ideally we would have a case mapping from ::Class -> T::Class and
107
+ # ::Module -> T::Module here but for backwards compatibility we
108
+ # don't have that, and instead have a special case in subtype_of_single?
109
109
  Simple.new(mod)
110
110
  end
111
111
 
@@ -33,7 +33,7 @@ module T::Types
33
33
  # overrides Base
34
34
  private def subtype_of_single?(type)
35
35
  case type
36
- when TypedClass
36
+ when TypedClass, TypedModule
37
37
  # treat like generics are erased
38
38
  true
39
39
  when Simple
@@ -38,14 +38,12 @@ module T::Types
38
38
  return false unless obj.is_a?(Enumerable)
39
39
  case obj
40
40
  when Array
41
- begin
42
- it = 0
43
- while it < obj.count
44
- return false unless type.recursively_valid?(obj[it])
45
- it += 1
46
- end
47
- true
41
+ it = 0
42
+ while it < obj.count
43
+ return false unless type.recursively_valid?(obj[it])
44
+ it += 1
48
45
  end
46
+ true
49
47
  when Hash
50
48
  type_ = self.type
51
49
  return false unless type_.is_a?(FixedArray)
@@ -168,11 +166,7 @@ module T::Types
168
166
  obj.class
169
167
  else
170
168
  # This is a specialized enumerable type, just return the class.
171
- if T::Configuration::AT_LEAST_RUBY_2_7
172
- Object.instance_method(:class).bind_call(obj)
173
- else
174
- Object.instance_method(:class).bind(obj).call # rubocop:disable Performance/BindCall
175
- end
169
+ Object.instance_method(:class).bind_call(obj)
176
170
  end
177
171
  end
178
172
 
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ module T::Types
5
+ class TypedModule < T::Types::Base
6
+ def initialize(type)
7
+ @inner_type = type
8
+ end
9
+
10
+ def type
11
+ @type ||= T::Utils.coerce(@inner_type)
12
+ end
13
+
14
+ def build_type
15
+ type
16
+ nil
17
+ end
18
+
19
+ # overrides Base
20
+ def name
21
+ "T::Module[#{type.name}]"
22
+ end
23
+
24
+ def underlying_class
25
+ Module
26
+ end
27
+
28
+ # overrides Base
29
+ def valid?(obj)
30
+ Module.===(obj)
31
+ end
32
+
33
+ # overrides Base
34
+ private def subtype_of_single?(type)
35
+ case type
36
+ when TypedModule
37
+ # treat like generics are erased
38
+ true
39
+ when Simple
40
+ Module <= type.raw_type
41
+ else
42
+ false
43
+ end
44
+ end
45
+
46
+ module Private
47
+ module Pool
48
+ CACHE_FROZEN_OBJECTS =
49
+ begin
50
+ ObjectSpace::WeakMap.new[1] = 1
51
+ true # Ruby 2.7 and newer
52
+ rescue ArgumentError
53
+ false # Ruby 2.6 and older
54
+ end
55
+
56
+ @cache = ObjectSpace::WeakMap.new
57
+
58
+ def self.type_for_module(mod)
59
+ cached = @cache[mod]
60
+ return cached if cached
61
+
62
+ type = TypedModule.new(mod)
63
+
64
+ if CACHE_FROZEN_OBJECTS || (!mod.frozen? && !type.frozen?)
65
+ @cache[mod] = type
66
+ end
67
+ type
68
+ end
69
+ end
70
+ end
71
+
72
+ class Untyped < TypedModule
73
+ def initialize
74
+ super(T::Types::Untyped::Private::INSTANCE)
75
+ end
76
+
77
+ def freeze
78
+ build_type # force lazy initialization before freezing the object
79
+ super
80
+ end
81
+
82
+ module Private
83
+ INSTANCE = Untyped.new.freeze
84
+ end
85
+ end
86
+
87
+ class Anything < TypedModule
88
+ def initialize
89
+ super(T.anything)
90
+ end
91
+
92
+ def freeze
93
+ build_type # force lazy initialization before freezing the object
94
+ super
95
+ end
96
+
97
+ module Private
98
+ INSTANCE = Anything.new.freeze
99
+ end
100
+ end
101
+ end
102
+ end
@@ -14,7 +14,6 @@ module T::Types
14
14
 
15
15
  # overrides Base
16
16
  def recursively_valid?(obj)
17
- # Re-implements non_forcing_is_a?
18
17
  return false if Object.autoload?(:Set) # Set is meant to be autoloaded but not yet loaded, this value can't be a Set
19
18
  return false unless Object.const_defined?(:Set) # Set is not loaded yet
20
19
  obj.is_a?(Set) && super
@@ -22,7 +21,6 @@ module T::Types
22
21
 
23
22
  # overrides Base
24
23
  def valid?(obj)
25
- # Re-implements non_forcing_is_a?
26
24
  return false if Object.autoload?(:Set) # Set is meant to be autoloaded but not yet loaded, this value can't be a Set
27
25
  return false unless Object.const_defined?(:Set) # Set is not loaded yet
28
26
  obj.is_a?(Set)
@@ -41,7 +39,6 @@ module T::Types
41
39
  end
42
40
 
43
41
  def valid?(obj)
44
- # Re-implements non_forcing_is_a?
45
42
  return false if Object.autoload?(:Set) # Set is meant to be autoloaded but not yet loaded, this value can't be a Set
46
43
  return false unless Object.const_defined?(:Set) # Set is not loaded yet
47
44
  obj.is_a?(Set)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sorbet-runtime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.12652
4
+ version: 0.6.12730
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-10-22 00:00:00.000000000 Z
11
+ date: 2025-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 1.57.1
61
+ version: 1.81.6
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 1.57.1
68
+ version: 1.81.6
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop-performance
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -165,7 +165,6 @@ files:
165
165
  - lib/types/enum.rb
166
166
  - lib/types/generic.rb
167
167
  - lib/types/helpers.rb
168
- - lib/types/non_forcing_constants.rb
169
168
  - lib/types/private/abstract/data.rb
170
169
  - lib/types/private/abstract/declare.rb
171
170
  - lib/types/private/abstract/hooks.rb
@@ -177,7 +176,6 @@ files:
177
176
  - lib/types/private/final.rb
178
177
  - lib/types/private/methods/_methods.rb
179
178
  - lib/types/private/methods/call_validation.rb
180
- - lib/types/private/methods/call_validation_2_6.rb
181
179
  - lib/types/private/methods/call_validation_2_7.rb
182
180
  - lib/types/private/methods/decl_builder.rb
183
181
  - lib/types/private/methods/modes.rb
@@ -238,6 +236,7 @@ files:
238
236
  - lib/types/types/typed_enumerator_chain.rb
239
237
  - lib/types/types/typed_enumerator_lazy.rb
240
238
  - lib/types/types/typed_hash.rb
239
+ - lib/types/types/typed_module.rb
241
240
  - lib/types/types/typed_range.rb
242
241
  - lib/types/types/typed_set.rb
243
242
  - lib/types/types/union.rb
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
- # typed: strict
3
-
4
- module T::NonForcingConstants
5
- # NOTE: This method is documented on the RBI in Sorbet's payload, so that it
6
- # shows up in the hover/completion documentation via LSP.
7
- T::Sig::WithoutRuntime.sig { params(val: BasicObject, klass: String).returns(T::Boolean) }
8
- def self.non_forcing_is_a?(val, klass)
9
- method_name = "T::NonForcingConstants.non_forcing_is_a?"
10
- if klass.empty?
11
- raise ArgumentError.new("The string given to `#{method_name}` must not be empty")
12
- end
13
-
14
- current_klass = T.let(nil, T.nilable(Module))
15
- current_prefix = T.let(nil, T.nilable(String))
16
-
17
- parts = klass.split('::')
18
- parts.each do |part|
19
- if current_klass.nil?
20
- # First iteration
21
- if part != ""
22
- raise ArgumentError.new("The string given to `#{method_name}` must be an absolute constant reference that starts with `::`")
23
- end
24
-
25
- current_klass = Object
26
- current_prefix = ''
27
-
28
- # if this had a :: prefix, then there's no more loading to
29
- # do---skip to the next one
30
- next
31
- end
32
-
33
- if current_klass.autoload?(part)
34
- # There's an autoload registered for that constant, which means it's not
35
- # yet loaded. `value` can't be an instance of something not yet loaded.
36
- return false
37
- end
38
-
39
- # Sorbet guarantees that the string is an absolutely resolved name.
40
- search_inheritance_chain = false
41
- if !current_klass.const_defined?(part, search_inheritance_chain)
42
- return false
43
- end
44
-
45
- current_klass = current_klass.const_get(part)
46
- current_prefix = "#{current_prefix}::#{part}"
47
-
48
- if !Module.===(current_klass)
49
- raise ArgumentError.new("#{current_prefix} is not a class or module")
50
- end
51
- end
52
-
53
- current_klass.===(val)
54
- end
55
- end