sorbet-runtime 0.6.12689 → 0.6.12798
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 +4 -4
- data/lib/sorbet-runtime.rb +1 -1
- data/lib/types/_types.rb +12 -0
- data/lib/types/configuration.rb +1 -1
- data/lib/types/enum.rb +1 -1
- data/lib/types/props/custom_type.rb +1 -1
- data/lib/types/props/decorator.rb +14 -12
- data/lib/types/props/private/apply_default.rb +4 -4
- data/lib/types/props/private/serde_transform.rb +4 -4
- data/lib/types/props/private/setter_factory.rb +9 -9
- data/lib/types/props/type_validation.rb +2 -2
- data/lib/types/types/class_of.rb +1 -1
- data/lib/types/types/simple.rb +4 -4
- data/lib/types/types/typed_class.rb +1 -1
- data/lib/types/types/typed_module.rb +102 -0
- data/lib/types/types/typed_set.rb +0 -3
- metadata +3 -3
- data/lib/types/non_forcing_constants.rb +0 -55
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 73a167fb61378c7eb261ccc15d0d1ad2a1ca7a9d9db1816ae74b83d292e6eae1
|
|
4
|
+
data.tar.gz: de1711647a5c5f7b3f47151f6fd57f761bea91093db902807013c0abe5854c14
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: abbcf8329b9bde8d238df649332083fed79f6175c31204a639d724a48b152614abcf942f9348ba5feb4e123e24957b42d9e36d61786024e641644091e2577c9b
|
|
7
|
+
data.tar.gz: 58b41fa8cf2452a463bed2ac64007be0e93190b281a4475c96d39c04e3f971c562c32f0a0cae9348a8d8a8fbc567541b4a504a7c116c24eb1f2d4e35ba0ff844
|
data/lib/sorbet-runtime.rb
CHANGED
|
@@ -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
|
data/lib/types/configuration.rb
CHANGED
|
@@ -455,7 +455,7 @@ module T::Configuration
|
|
|
455
455
|
|
|
456
456
|
# Set to override the default behavior for converting types
|
|
457
457
|
# to names in generated code. Used by the runtime implementation
|
|
458
|
-
# associated with `--
|
|
458
|
+
# associated with `--sorbet-packages` mode.
|
|
459
459
|
#
|
|
460
460
|
# @param [Lambda, Proc, nil] handler Proc that converts a type (Class/Module)
|
|
461
461
|
# to a String (pass nil to reset to default behavior)
|
data/lib/types/enum.rb
CHANGED
|
@@ -50,7 +50,7 @@ module T::Props
|
|
|
50
50
|
sig { abstract.params(scalar: T.untyped).returns(T.untyped).checked(:never) }
|
|
51
51
|
def deserialize(scalar); end
|
|
52
52
|
|
|
53
|
-
sig { override.params(_base: Module).void }
|
|
53
|
+
sig { override.params(_base: T::Module[T.anything]).void }
|
|
54
54
|
def self.included(_base)
|
|
55
55
|
super
|
|
56
56
|
|
|
@@ -13,8 +13,10 @@ class T::Props::Decorator
|
|
|
13
13
|
Rules = T.type_alias { T::Hash[Symbol, T.untyped] }
|
|
14
14
|
DecoratedInstance = T.type_alias { Object } # Would be T::Props, but that produces circular reference errors in some circumstances
|
|
15
15
|
PropType = T.type_alias { T::Types::Base }
|
|
16
|
-
PropTypeOrClass = T.type_alias { T.any(PropType, Module) }
|
|
16
|
+
PropTypeOrClass = T.type_alias { T.any(PropType, T::Module[T.anything]) }
|
|
17
17
|
OverrideRules = T.type_alias { T::Hash[Symbol, {allow_incompatible: T::Boolean}] }
|
|
18
|
+
DecoratedClassType = T.type_alias { T.all(T::Module[T.anything], T::Props::ClassMethods) }
|
|
19
|
+
private_constant :DecoratedClassType
|
|
18
20
|
|
|
19
21
|
class NoRulesError < StandardError; end
|
|
20
22
|
|
|
@@ -38,7 +40,7 @@ class T::Props::Decorator
|
|
|
38
40
|
|
|
39
41
|
sig { params(klass: T.untyped).void.checked(:never) }
|
|
40
42
|
def initialize(klass)
|
|
41
|
-
@class = T.let(klass,
|
|
43
|
+
@class = T.let(klass, DecoratedClassType)
|
|
42
44
|
@class.plugins.each do |mod|
|
|
43
45
|
T::Props::Plugin::Private.apply_decorator_methods(mod, self)
|
|
44
46
|
end
|
|
@@ -102,7 +104,7 @@ class T::Props::Decorator
|
|
|
102
104
|
end
|
|
103
105
|
|
|
104
106
|
# checked(:never) - O(prop accesses)
|
|
105
|
-
sig { returns(
|
|
107
|
+
sig { returns(DecoratedClassType).checked(:never) }
|
|
106
108
|
def decorated_class
|
|
107
109
|
@class
|
|
108
110
|
end
|
|
@@ -207,7 +209,7 @@ class T::Props::Decorator
|
|
|
207
209
|
params(
|
|
208
210
|
instance: DecoratedInstance,
|
|
209
211
|
prop: Symbol,
|
|
210
|
-
foreign_class: Module,
|
|
212
|
+
foreign_class: T::Module[T.anything],
|
|
211
213
|
rules: Rules,
|
|
212
214
|
opts: T::Hash[Symbol, T.untyped],
|
|
213
215
|
)
|
|
@@ -226,7 +228,7 @@ class T::Props::Decorator
|
|
|
226
228
|
sig do
|
|
227
229
|
params(
|
|
228
230
|
name: Symbol,
|
|
229
|
-
cls: Module,
|
|
231
|
+
cls: T::Module[T.anything],
|
|
230
232
|
rules: Rules,
|
|
231
233
|
type: PropTypeOrClass
|
|
232
234
|
)
|
|
@@ -277,7 +279,7 @@ class T::Props::Decorator
|
|
|
277
279
|
end
|
|
278
280
|
|
|
279
281
|
# This converts the type from a T::Type to a regular old ruby class.
|
|
280
|
-
sig { params(type: T::Types::Base).returns(Module).checked(:never) }
|
|
282
|
+
sig { params(type: T::Types::Base).returns(T::Module[T.anything]).checked(:never) }
|
|
281
283
|
private def convert_type_to_class(type)
|
|
282
284
|
case type
|
|
283
285
|
when T::Types::TypedArray, T::Types::FixedArray
|
|
@@ -586,7 +588,7 @@ class T::Props::Decorator
|
|
|
586
588
|
sig do
|
|
587
589
|
params(
|
|
588
590
|
prop_name: Symbol,
|
|
589
|
-
prop_cls: Module,
|
|
591
|
+
prop_cls: T::Module[T.anything],
|
|
590
592
|
rules: Rules,
|
|
591
593
|
foreign: T.untyped,
|
|
592
594
|
)
|
|
@@ -629,10 +631,10 @@ class T::Props::Decorator
|
|
|
629
631
|
#
|
|
630
632
|
# This gets called when a module or class that extends T::Props gets included, extended,
|
|
631
633
|
# prepended, or inherited.
|
|
632
|
-
sig { params(child: Module).void.checked(:never) }
|
|
634
|
+
sig { params(child: T::Module[T.anything]).void.checked(:never) }
|
|
633
635
|
def model_inherited(child)
|
|
634
636
|
child.extend(T::Props::ClassMethods)
|
|
635
|
-
child = T.cast(child,
|
|
637
|
+
child = T.cast(child, DecoratedClassType)
|
|
636
638
|
|
|
637
639
|
child.plugins.concat(decorated_class.plugins)
|
|
638
640
|
decorated_class.plugins.each do |mod|
|
|
@@ -719,19 +721,19 @@ class T::Props::Decorator
|
|
|
719
721
|
result
|
|
720
722
|
end
|
|
721
723
|
|
|
722
|
-
sig { params(child:
|
|
724
|
+
sig { params(child: DecoratedClassType, prop: Symbol).returns(T::Boolean).checked(:never) }
|
|
723
725
|
private def clobber_getter?(child, prop)
|
|
724
726
|
!!(child.decorator.method(:prop_get).owner != method(:prop_get).owner &&
|
|
725
727
|
child.instance_method(prop).source_location&.first == __FILE__)
|
|
726
728
|
end
|
|
727
729
|
|
|
728
|
-
sig { params(child:
|
|
730
|
+
sig { params(child: DecoratedClassType, prop: Symbol).returns(T::Boolean).checked(:never) }
|
|
729
731
|
private def clobber_setter?(child, prop)
|
|
730
732
|
!!(child.decorator.method(:prop_set).owner != method(:prop_set).owner &&
|
|
731
733
|
child.instance_method("#{prop}=").source_location&.first == __FILE__)
|
|
732
734
|
end
|
|
733
735
|
|
|
734
|
-
sig { params(mod: Module).void.checked(:never) }
|
|
736
|
+
sig { params(mod: T::Module[T.anything]).void.checked(:never) }
|
|
735
737
|
def plugin(mod)
|
|
736
738
|
decorated_class.plugins << mod
|
|
737
739
|
T::Props::Plugin::Private.apply_class_methods(mod, decorated_class)
|
|
@@ -27,10 +27,10 @@ module T::Props
|
|
|
27
27
|
sig { abstract.params(instance: T.all(T::Props::Optional, Object)).void.checked(:never) }
|
|
28
28
|
def set_default(instance); end
|
|
29
29
|
|
|
30
|
-
NO_CLONE_TYPES = T.let([TrueClass, FalseClass, NilClass, Symbol, Numeric, T::Enum].freeze, T::Array[Module])
|
|
30
|
+
NO_CLONE_TYPES = T.let([TrueClass, FalseClass, NilClass, Symbol, Numeric, T::Enum].freeze, T::Array[T::Module[T.anything]])
|
|
31
31
|
|
|
32
32
|
# checked(:never) - Rules hash is expensive to check
|
|
33
|
-
sig { params(cls: Module, rules: T::Hash[Symbol, T.untyped]).returns(T.nilable(ApplyDefault)).checked(:never) }
|
|
33
|
+
sig { params(cls: T::Module[T.anything], rules: T::Hash[Symbol, T.untyped]).returns(T.nilable(ApplyDefault)).checked(:never) }
|
|
34
34
|
def self.for(cls, rules)
|
|
35
35
|
accessor_key = rules.fetch(:accessor_key)
|
|
36
36
|
setter = rules.fetch(:setter_proc)
|
|
@@ -138,7 +138,7 @@ module T::Props
|
|
|
138
138
|
# checked(:never) - We do this with `T.let` instead
|
|
139
139
|
sig do
|
|
140
140
|
params(
|
|
141
|
-
cls: Module,
|
|
141
|
+
cls: T::Module[T.anything],
|
|
142
142
|
factory: T.any(Proc, Method),
|
|
143
143
|
accessor_key: Symbol,
|
|
144
144
|
setter_proc: SetterFactory::SetterProc,
|
|
@@ -147,7 +147,7 @@ module T::Props
|
|
|
147
147
|
.checked(:never)
|
|
148
148
|
end
|
|
149
149
|
def initialize(cls, factory, accessor_key, setter_proc)
|
|
150
|
-
@class = T.let(cls, Module)
|
|
150
|
+
@class = T.let(cls, T::Module[T.anything])
|
|
151
151
|
@factory = T.let(factory, T.any(Proc, Method))
|
|
152
152
|
super(accessor_key, setter_proc)
|
|
153
153
|
end
|
|
@@ -20,7 +20,7 @@ module T::Props
|
|
|
20
20
|
|
|
21
21
|
NO_TRANSFORM_TYPES = T.let(
|
|
22
22
|
[TrueClass, FalseClass, NilClass, Symbol, String].freeze,
|
|
23
|
-
T::Array[Module],
|
|
23
|
+
T::Array[T::Module[T.anything]],
|
|
24
24
|
)
|
|
25
25
|
private_constant :NO_TRANSFORM_TYPES
|
|
26
26
|
|
|
@@ -151,7 +151,7 @@ module T::Props
|
|
|
151
151
|
end
|
|
152
152
|
end
|
|
153
153
|
|
|
154
|
-
sig { params(varname: String, type: Module, mode: ModeType).returns(String).checked(:never) }
|
|
154
|
+
sig { params(varname: String, type: T::Module[T.anything], mode: ModeType).returns(String).checked(:never) }
|
|
155
155
|
private_class_method def self.handle_serializable_subtype(varname, type, mode)
|
|
156
156
|
case mode
|
|
157
157
|
when Serialize
|
|
@@ -164,7 +164,7 @@ module T::Props
|
|
|
164
164
|
end
|
|
165
165
|
end
|
|
166
166
|
|
|
167
|
-
sig { params(varname: String, type: Module, mode: ModeType).returns(String).checked(:never) }
|
|
167
|
+
sig { params(varname: String, type: T::Module[T.anything], mode: ModeType).returns(String).checked(:never) }
|
|
168
168
|
private_class_method def self.handle_custom_type(varname, type, mode)
|
|
169
169
|
case mode
|
|
170
170
|
when Serialize
|
|
@@ -177,7 +177,7 @@ module T::Props
|
|
|
177
177
|
end
|
|
178
178
|
end
|
|
179
179
|
|
|
180
|
-
sig { params(type: Module).returns(T.nilable(String)).checked(:never) }
|
|
180
|
+
sig { params(type: T::Module[T.anything]).returns(T.nilable(String)).checked(:never) }
|
|
181
181
|
private_class_method def self.module_name(type)
|
|
182
182
|
T::Configuration.module_name_mangler.call(type)
|
|
183
183
|
end
|
|
@@ -12,7 +12,7 @@ module T::Props
|
|
|
12
12
|
|
|
13
13
|
sig do
|
|
14
14
|
params(
|
|
15
|
-
klass: T.all(Module, T::Props::ClassMethods),
|
|
15
|
+
klass: T.all(T::Module[T.anything], T::Props::ClassMethods),
|
|
16
16
|
prop: Symbol,
|
|
17
17
|
rules: T::Hash[Symbol, T.untyped]
|
|
18
18
|
)
|
|
@@ -53,8 +53,8 @@ module T::Props
|
|
|
53
53
|
params(
|
|
54
54
|
prop: Symbol,
|
|
55
55
|
accessor_key: Symbol,
|
|
56
|
-
non_nil_type: Module,
|
|
57
|
-
klass: T.all(Module, T::Props::ClassMethods),
|
|
56
|
+
non_nil_type: T::Module[T.anything],
|
|
57
|
+
klass: T.all(T::Module[T.anything], T::Props::ClassMethods),
|
|
58
58
|
)
|
|
59
59
|
.returns([SetterProc, ValueValidationProc])
|
|
60
60
|
end
|
|
@@ -89,7 +89,7 @@ module T::Props
|
|
|
89
89
|
prop: Symbol,
|
|
90
90
|
accessor_key: Symbol,
|
|
91
91
|
non_nil_type: T::Types::Base,
|
|
92
|
-
klass: T.all(Module, T::Props::ClassMethods),
|
|
92
|
+
klass: T.all(T::Module[T.anything], T::Props::ClassMethods),
|
|
93
93
|
validate: T.nilable(ValidateProc)
|
|
94
94
|
)
|
|
95
95
|
.returns([SetterProc, ValueValidationProc])
|
|
@@ -138,8 +138,8 @@ module T::Props
|
|
|
138
138
|
params(
|
|
139
139
|
prop: Symbol,
|
|
140
140
|
accessor_key: Symbol,
|
|
141
|
-
non_nil_type: Module,
|
|
142
|
-
klass: T.all(Module, T::Props::ClassMethods),
|
|
141
|
+
non_nil_type: T::Module[T.anything],
|
|
142
|
+
klass: T.all(T::Module[T.anything], T::Props::ClassMethods),
|
|
143
143
|
)
|
|
144
144
|
.returns([SetterProc, ValueValidationProc])
|
|
145
145
|
end
|
|
@@ -174,7 +174,7 @@ module T::Props
|
|
|
174
174
|
prop: Symbol,
|
|
175
175
|
accessor_key: Symbol,
|
|
176
176
|
non_nil_type: T::Types::Base,
|
|
177
|
-
klass: T.all(Module, T::Props::ClassMethods),
|
|
177
|
+
klass: T.all(T::Module[T.anything], T::Props::ClassMethods),
|
|
178
178
|
validate: T.nilable(ValidateProc),
|
|
179
179
|
)
|
|
180
180
|
.returns([SetterProc, ValueValidationProc])
|
|
@@ -225,9 +225,9 @@ module T::Props
|
|
|
225
225
|
|
|
226
226
|
sig do
|
|
227
227
|
params(
|
|
228
|
-
klass: T.all(Module, T::Props::ClassMethods),
|
|
228
|
+
klass: T.all(T::Module[T.anything], T::Props::ClassMethods),
|
|
229
229
|
prop: Symbol,
|
|
230
|
-
type: T.any(T::Types::Base, Module),
|
|
230
|
+
type: T.any(T::Types::Base, T::Module[T.anything]),
|
|
231
231
|
val: T.untyped,
|
|
232
232
|
)
|
|
233
233
|
.void
|
|
@@ -20,9 +20,9 @@ module T::Props::TypeValidation
|
|
|
20
20
|
sig do
|
|
21
21
|
params(
|
|
22
22
|
name: T.any(Symbol, String),
|
|
23
|
-
_cls: Module,
|
|
23
|
+
_cls: T::Module[T.anything],
|
|
24
24
|
rules: T::Hash[Symbol, T.untyped],
|
|
25
|
-
type: T.any(T::Types::Base, Module)
|
|
25
|
+
type: T.any(T::Types::Base, T::Module[T.anything])
|
|
26
26
|
)
|
|
27
27
|
.void
|
|
28
28
|
.checked(:never)
|
data/lib/types/types/class_of.rb
CHANGED
data/lib/types/types/simple.rb
CHANGED
|
@@ -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
|
|
107
|
-
# but for backwards compatibility we
|
|
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
|
|
|
@@ -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.
|
|
4
|
+
version: 0.6.12798
|
|
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
|
+
date: 2025-11-28 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
|