sorbet-runtime 0.6.12690 → 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: 639b70e663f6372b6912fa96582af60ac52db5bf07b63125d65b264ff382095c
4
- data.tar.gz: dcf3eb8033a59058e1840692ca196b0b046ff43bbbebe67fcaa759185b4570ae
3
+ metadata.gz: d7a9be1c70e2968dd0cf8382b60a6240101bdd6dda73fa9cc6d7ff4f24c09c01
4
+ data.tar.gz: fca2152b203801b6fd5a161b28c6ddf927cafe3f58773089b5611a8a6ca51a46
5
5
  SHA512:
6
- metadata.gz: 05af3b63b667ca36c946a29a663754dc3304717f9137d2b0c03e46fa0dc6b81fa21a95cce5f03cf8dd29092313721615242085cf86daf914f334bb6489bb5337
7
- data.tar.gz: 320828be9bb5be8770fcaf97123dce71bfa7895a604cead0bef0c7ee59cb16544425927f4153fed240de127677e73becfd92f6d029d40d5834bb57e430857505
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
@@ -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
@@ -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.12690
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-11-01 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
@@ -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
@@ -237,6 +236,7 @@ files:
237
236
  - lib/types/types/typed_enumerator_chain.rb
238
237
  - lib/types/types/typed_enumerator_lazy.rb
239
238
  - lib/types/types/typed_hash.rb
239
+ - lib/types/types/typed_module.rb
240
240
  - lib/types/types/typed_range.rb
241
241
  - lib/types/types/typed_set.rb
242
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