sorbet-runtime 0.5.11170 → 0.5.11175
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/types/private/methods/_methods.rb +6 -3
- data/lib/types/private/methods/signature.rb +9 -0
- data/lib/types/private/types/not_typed.rb +4 -0
- data/lib/types/private/types/string_holder.rb +4 -0
- data/lib/types/private/types/type_alias.rb +4 -0
- data/lib/types/private/types/void.rb +4 -0
- data/lib/types/types/anything.rb +4 -0
- data/lib/types/types/attached_class.rb +4 -0
- data/lib/types/types/base.rb +6 -0
- data/lib/types/types/class_of.rb +4 -0
- data/lib/types/types/enum.rb +4 -0
- data/lib/types/types/fixed_array.rb +19 -12
- data/lib/types/types/fixed_hash.rb +16 -9
- data/lib/types/types/intersection.rb +13 -6
- data/lib/types/types/noreturn.rb +4 -0
- data/lib/types/types/proc.rb +19 -9
- data/lib/types/types/self_type.rb +4 -0
- data/lib/types/types/simple.rb +4 -0
- data/lib/types/types/t_enum.rb +4 -0
- data/lib/types/types/type_parameter.rb +4 -0
- data/lib/types/types/type_variable.rb +4 -0
- data/lib/types/types/typed_array.rb +6 -1
- data/lib/types/types/typed_class.rb +21 -4
- data/lib/types/types/typed_enumerable.rb +18 -11
- data/lib/types/types/typed_enumerator.rb +1 -3
- data/lib/types/types/typed_enumerator_chain.rb +1 -3
- data/lib/types/types/typed_enumerator_lazy.rb +1 -3
- data/lib/types/types/typed_hash.rb +23 -7
- data/lib/types/types/typed_range.rb +1 -3
- data/lib/types/types/typed_set.rb +1 -3
- data/lib/types/types/union.rb +12 -5
- data/lib/types/types/untyped.rb +4 -0
- data/lib/types/utils.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 01fe1cd8291711ea4e0483c920c7d79344710e14e55807132409bd8afd572e75
|
|
4
|
+
data.tar.gz: 4c8b7c9d278e6b4320efbf57c87e46d238346fa75bb231cd3572c2f568d3e913
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cca6ac69e53f520671d1378633f79474c910984bfc0279c4fd366aa8a086cb18bcb6c728b797529c82eb57f884041763d8fcd3f872fd562356347875f98005f6
|
|
7
|
+
data.tar.gz: e43cb943fb0336c3c436b0a4b25316deccddd6a0c58e05f4c4735097c028c97aed4629e43e589e0d2572e57afec5cec08b6d14b7318633ca4f3bf15c75666038
|
|
@@ -428,7 +428,7 @@ module T::Private::Methods
|
|
|
428
428
|
run_sig_block_for_key(method_to_key(method))
|
|
429
429
|
end
|
|
430
430
|
|
|
431
|
-
private_class_method def self.run_sig_block_for_key(key)
|
|
431
|
+
private_class_method def self.run_sig_block_for_key(key, force_type_init: false)
|
|
432
432
|
blk = @sig_wrappers[key]
|
|
433
433
|
if !blk
|
|
434
434
|
sig = @signatures_by_method[key]
|
|
@@ -451,14 +451,17 @@ module T::Private::Methods
|
|
|
451
451
|
end
|
|
452
452
|
|
|
453
453
|
@sig_wrappers.delete(key)
|
|
454
|
+
|
|
455
|
+
sig.force_type_init if force_type_init
|
|
456
|
+
|
|
454
457
|
sig
|
|
455
458
|
end
|
|
456
459
|
|
|
457
|
-
def self.run_all_sig_blocks
|
|
460
|
+
def self.run_all_sig_blocks(force_type_init: true)
|
|
458
461
|
loop do
|
|
459
462
|
break if @sig_wrappers.empty?
|
|
460
463
|
key, = @sig_wrappers.first
|
|
461
|
-
run_sig_block_for_key(key)
|
|
464
|
+
run_sig_block_for_key(key, force_type_init: force_type_init)
|
|
462
465
|
end
|
|
463
466
|
end
|
|
464
467
|
|
|
@@ -245,6 +245,15 @@ class T::Private::Methods::Signature
|
|
|
245
245
|
"#{@method} at #{loc}"
|
|
246
246
|
end
|
|
247
247
|
|
|
248
|
+
def force_type_init
|
|
249
|
+
@arg_types.each {|_, type| type.build_type}
|
|
250
|
+
@kwarg_types.each {|_, type| type.build_type}
|
|
251
|
+
@block_type&.build_type
|
|
252
|
+
@rest_type&.build_type
|
|
253
|
+
@keyrest_type&.build_type
|
|
254
|
+
@return_type.build_type
|
|
255
|
+
end
|
|
256
|
+
|
|
248
257
|
EMPTY_LIST = [].freeze
|
|
249
258
|
EMPTY_HASH = {}.freeze
|
|
250
259
|
end
|
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
class T::Private::Types::NotTyped < T::Types::Base
|
|
7
7
|
ERROR_MESSAGE = "Validation is being done on a `NotTyped`. Please report this bug at https://github.com/sorbet/sorbet/issues"
|
|
8
8
|
|
|
9
|
+
def build_type
|
|
10
|
+
nil
|
|
11
|
+
end
|
|
12
|
+
|
|
9
13
|
# overrides Base
|
|
10
14
|
def name
|
|
11
15
|
"<NOT-TYPED>"
|
data/lib/types/types/anything.rb
CHANGED
data/lib/types/types/base.rb
CHANGED
|
@@ -33,6 +33,12 @@ module T::Types
|
|
|
33
33
|
raise NotImplementedError
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
+
# Force any lazy initialization that this type might need to do
|
|
37
|
+
# It's unusual to call this directly; you probably want to call it indirectly via `T::Utils.run_all_sig_blocks`.
|
|
38
|
+
def build_type
|
|
39
|
+
raise NotImplementedError
|
|
40
|
+
end
|
|
41
|
+
|
|
36
42
|
# Equality is based on name, so be sure the name reflects all relevant state when implementing.
|
|
37
43
|
def name
|
|
38
44
|
raise NotImplementedError
|
data/lib/types/types/class_of.rb
CHANGED
data/lib/types/types/enum.rb
CHANGED
|
@@ -6,23 +6,30 @@ module T::Types
|
|
|
6
6
|
# Takes a list of types. Validates each item in an array using the type in the same position
|
|
7
7
|
# in the list.
|
|
8
8
|
class FixedArray < Base
|
|
9
|
-
attr_reader :types
|
|
10
|
-
|
|
11
9
|
def initialize(types)
|
|
12
|
-
@
|
|
10
|
+
@inner_types = types
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def types
|
|
14
|
+
@types ||= @inner_types.map {|type| T::Utils.coerce(type)}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def build_type
|
|
18
|
+
types
|
|
19
|
+
nil
|
|
13
20
|
end
|
|
14
21
|
|
|
15
22
|
# overrides Base
|
|
16
23
|
def name
|
|
17
|
-
"[#{
|
|
24
|
+
"[#{types.join(', ')}]"
|
|
18
25
|
end
|
|
19
26
|
|
|
20
27
|
# overrides Base
|
|
21
28
|
def recursively_valid?(obj)
|
|
22
|
-
if obj.is_a?(Array) && obj.length ==
|
|
29
|
+
if obj.is_a?(Array) && obj.length == types.length
|
|
23
30
|
i = 0
|
|
24
|
-
while i <
|
|
25
|
-
if
|
|
31
|
+
while i < types.length
|
|
32
|
+
if !types[i].recursively_valid?(obj[i])
|
|
26
33
|
return false
|
|
27
34
|
end
|
|
28
35
|
i += 1
|
|
@@ -35,10 +42,10 @@ module T::Types
|
|
|
35
42
|
|
|
36
43
|
# overrides Base
|
|
37
44
|
def valid?(obj)
|
|
38
|
-
if obj.is_a?(Array) && obj.length ==
|
|
45
|
+
if obj.is_a?(Array) && obj.length == types.length
|
|
39
46
|
i = 0
|
|
40
|
-
while i <
|
|
41
|
-
if
|
|
47
|
+
while i < types.length
|
|
48
|
+
if !types[i].valid?(obj[i])
|
|
42
49
|
return false
|
|
43
50
|
end
|
|
44
51
|
i += 1
|
|
@@ -56,7 +63,7 @@ module T::Types
|
|
|
56
63
|
# Properly speaking, covariance here is unsound since arrays
|
|
57
64
|
# can be mutated, but sorbet implements covariant tuples for
|
|
58
65
|
# ease of adoption.
|
|
59
|
-
|
|
66
|
+
types.size == other.types.size && types.zip(other.types).all? do |t1, t2|
|
|
60
67
|
t1.subtype_of?(t2)
|
|
61
68
|
end
|
|
62
69
|
when TypedArray
|
|
@@ -85,7 +92,7 @@ module T::Types
|
|
|
85
92
|
# overrides Base
|
|
86
93
|
def describe_obj(obj)
|
|
87
94
|
if obj.is_a?(Array)
|
|
88
|
-
if obj.length ==
|
|
95
|
+
if obj.length == types.length
|
|
89
96
|
item_classes = obj.map(&:class).join(', ')
|
|
90
97
|
"type [#{item_classes}]"
|
|
91
98
|
else
|
|
@@ -5,30 +5,37 @@ module T::Types
|
|
|
5
5
|
# Takes a hash of types. Validates each item in a hash using the type in the same position
|
|
6
6
|
# in the list.
|
|
7
7
|
class FixedHash < Base
|
|
8
|
-
attr_reader :types
|
|
9
|
-
|
|
10
8
|
def initialize(types)
|
|
11
|
-
@
|
|
9
|
+
@inner_types = types
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def types
|
|
13
|
+
@types ||= @inner_types.transform_values {|v| T::Utils.coerce(v)}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def build_type
|
|
17
|
+
types
|
|
18
|
+
nil
|
|
12
19
|
end
|
|
13
20
|
|
|
14
21
|
# overrides Base
|
|
15
22
|
def name
|
|
16
|
-
serialize_hash(
|
|
23
|
+
serialize_hash(types)
|
|
17
24
|
end
|
|
18
25
|
|
|
19
26
|
# overrides Base
|
|
20
27
|
def recursively_valid?(obj)
|
|
21
28
|
return false unless obj.is_a?(Hash)
|
|
22
|
-
return false if
|
|
23
|
-
return false if obj.any? {|key, _|
|
|
29
|
+
return false if types.any? {|key, type| !type.recursively_valid?(obj[key])}
|
|
30
|
+
return false if obj.any? {|key, _| !types[key]}
|
|
24
31
|
true
|
|
25
32
|
end
|
|
26
33
|
|
|
27
34
|
# overrides Base
|
|
28
35
|
def valid?(obj)
|
|
29
36
|
return false unless obj.is_a?(Hash)
|
|
30
|
-
return false if
|
|
31
|
-
return false if obj.any? {|key, _|
|
|
37
|
+
return false if types.any? {|key, type| !type.valid?(obj[key])}
|
|
38
|
+
return false if obj.any? {|key, _| !types[key]}
|
|
32
39
|
true
|
|
33
40
|
end
|
|
34
41
|
|
|
@@ -37,7 +44,7 @@ module T::Types
|
|
|
37
44
|
case other
|
|
38
45
|
when FixedHash
|
|
39
46
|
# Using `subtype_of?` here instead of == would be unsound
|
|
40
|
-
|
|
47
|
+
types == other.types
|
|
41
48
|
when TypedHash
|
|
42
49
|
# warning: covariant hashes
|
|
43
50
|
|
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
module T::Types
|
|
5
5
|
# Takes a list of types. Validates that an object matches all of the types.
|
|
6
6
|
class Intersection < Base
|
|
7
|
-
attr_reader :types
|
|
8
|
-
|
|
9
7
|
def initialize(types)
|
|
10
|
-
@
|
|
8
|
+
@inner_types = types
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def types
|
|
12
|
+
@types ||= @inner_types.flat_map do |type|
|
|
11
13
|
type = T::Utils.resolve_alias(type)
|
|
12
14
|
if type.is_a?(Intersection)
|
|
13
15
|
# Simplify nested intersections (mostly so `name` returns a nicer value)
|
|
@@ -18,19 +20,24 @@ module T::Types
|
|
|
18
20
|
end.uniq
|
|
19
21
|
end
|
|
20
22
|
|
|
23
|
+
def build_type
|
|
24
|
+
types
|
|
25
|
+
nil
|
|
26
|
+
end
|
|
27
|
+
|
|
21
28
|
# overrides Base
|
|
22
29
|
def name
|
|
23
|
-
"T.all(#{
|
|
30
|
+
"T.all(#{types.map(&:name).compact.sort.join(', ')})"
|
|
24
31
|
end
|
|
25
32
|
|
|
26
33
|
# overrides Base
|
|
27
34
|
def recursively_valid?(obj)
|
|
28
|
-
|
|
35
|
+
types.all? {|type| type.recursively_valid?(obj)}
|
|
29
36
|
end
|
|
30
37
|
|
|
31
38
|
# overrides Base
|
|
32
39
|
def valid?(obj)
|
|
33
|
-
|
|
40
|
+
types.all? {|type| type.valid?(obj)}
|
|
34
41
|
end
|
|
35
42
|
|
|
36
43
|
# overrides Base
|
data/lib/types/types/noreturn.rb
CHANGED
data/lib/types/types/proc.rb
CHANGED
|
@@ -8,21 +8,31 @@ module T::Types
|
|
|
8
8
|
# At present, we only support fixed-arity procs with no optional or
|
|
9
9
|
# keyword arguments.
|
|
10
10
|
class Proc < Base
|
|
11
|
-
attr_reader :arg_types
|
|
12
|
-
attr_reader :returns
|
|
13
|
-
|
|
14
11
|
def initialize(arg_types, returns)
|
|
15
|
-
@
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
@inner_arg_types = arg_types
|
|
13
|
+
@inner_returns = returns
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def arg_types
|
|
17
|
+
@arg_types ||= @inner_arg_types.map do |key, raw_type|
|
|
18
|
+
[key, T::Utils.coerce(raw_type)]
|
|
19
|
+
end.to_h
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def returns
|
|
23
|
+
@returns ||= T::Utils.coerce(@inner_returns)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def build_type
|
|
27
|
+
arg_types
|
|
28
|
+
returns
|
|
29
|
+
nil
|
|
20
30
|
end
|
|
21
31
|
|
|
22
32
|
# overrides Base
|
|
23
33
|
def name
|
|
24
34
|
args = []
|
|
25
|
-
|
|
35
|
+
arg_types.each do |k, v|
|
|
26
36
|
args << "#{k}: #{v.name}"
|
|
27
37
|
end
|
|
28
38
|
"T.proc.params(#{args.join(', ')}).returns(#{returns})"
|
data/lib/types/types/simple.rb
CHANGED
data/lib/types/types/t_enum.rb
CHANGED
|
@@ -5,7 +5,7 @@ module T::Types
|
|
|
5
5
|
class TypedArray < TypedEnumerable
|
|
6
6
|
# overrides Base
|
|
7
7
|
def name
|
|
8
|
-
"T::Array[#{
|
|
8
|
+
"T::Array[#{type.name}]"
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def underlying_class
|
|
@@ -60,6 +60,11 @@ module T::Types
|
|
|
60
60
|
obj.is_a?(Array)
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
+
def freeze
|
|
64
|
+
build_type # force lazy initialization before freezing the object
|
|
65
|
+
super
|
|
66
|
+
end
|
|
67
|
+
|
|
63
68
|
module Private
|
|
64
69
|
INSTANCE = Untyped.new.freeze
|
|
65
70
|
end
|
|
@@ -3,15 +3,22 @@
|
|
|
3
3
|
|
|
4
4
|
module T::Types
|
|
5
5
|
class TypedClass < T::Types::Base
|
|
6
|
-
attr_reader :type
|
|
7
|
-
|
|
8
6
|
def initialize(type)
|
|
9
|
-
@
|
|
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
|
|
10
17
|
end
|
|
11
18
|
|
|
12
19
|
# overrides Base
|
|
13
20
|
def name
|
|
14
|
-
"T::Class[#{
|
|
21
|
+
"T::Class[#{type.name}]"
|
|
15
22
|
end
|
|
16
23
|
|
|
17
24
|
def underlying_class
|
|
@@ -67,6 +74,11 @@ module T::Types
|
|
|
67
74
|
super(T.untyped)
|
|
68
75
|
end
|
|
69
76
|
|
|
77
|
+
def freeze
|
|
78
|
+
build_type # force lazy initialization before freezing the object
|
|
79
|
+
super
|
|
80
|
+
end
|
|
81
|
+
|
|
70
82
|
module Private
|
|
71
83
|
INSTANCE = Untyped.new.freeze
|
|
72
84
|
end
|
|
@@ -77,6 +89,11 @@ module T::Types
|
|
|
77
89
|
super(T.anything)
|
|
78
90
|
end
|
|
79
91
|
|
|
92
|
+
def freeze
|
|
93
|
+
build_type # force lazy initialization before freezing the object
|
|
94
|
+
super
|
|
95
|
+
end
|
|
96
|
+
|
|
80
97
|
module Private
|
|
81
98
|
INSTANCE = Anything.new.freeze
|
|
82
99
|
end
|
|
@@ -6,10 +6,17 @@ module T::Types
|
|
|
6
6
|
# `case` statement below in `describe_obj` in order to get better
|
|
7
7
|
# error messages.
|
|
8
8
|
class TypedEnumerable < Base
|
|
9
|
-
attr_reader :type
|
|
10
|
-
|
|
11
9
|
def initialize(type)
|
|
12
|
-
@
|
|
10
|
+
@inner_type = type
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def type
|
|
14
|
+
@type ||= T::Utils.coerce(@inner_type)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def build_type
|
|
18
|
+
type
|
|
19
|
+
nil
|
|
13
20
|
end
|
|
14
21
|
|
|
15
22
|
def underlying_class
|
|
@@ -18,7 +25,7 @@ module T::Types
|
|
|
18
25
|
|
|
19
26
|
# overrides Base
|
|
20
27
|
def name
|
|
21
|
-
"T::Enumerable[#{
|
|
28
|
+
"T::Enumerable[#{type.name}]"
|
|
22
29
|
end
|
|
23
30
|
|
|
24
31
|
# overrides Base
|
|
@@ -34,20 +41,20 @@ module T::Types
|
|
|
34
41
|
begin
|
|
35
42
|
it = 0
|
|
36
43
|
while it < obj.count
|
|
37
|
-
return false unless
|
|
44
|
+
return false unless type.recursively_valid?(obj[it])
|
|
38
45
|
it += 1
|
|
39
46
|
end
|
|
40
47
|
true
|
|
41
48
|
end
|
|
42
49
|
when Hash
|
|
43
|
-
return false unless
|
|
44
|
-
types =
|
|
50
|
+
return false unless type.is_a?(FixedArray)
|
|
51
|
+
types = type.types
|
|
45
52
|
return false if types.count != 2
|
|
46
53
|
key_type = types[0]
|
|
47
54
|
value_type = types[1]
|
|
48
55
|
obj.each_pair do |key, val|
|
|
49
56
|
# Some objects (I'm looking at you Rack::Utils::HeaderHash) don't
|
|
50
|
-
# iterate over a [key, value] array, so we can't juse use the
|
|
57
|
+
# iterate over a [key, value] array, so we can't juse use the type.recursively_valid?(v)
|
|
51
58
|
return false if !key_type.recursively_valid?(key) || !value_type.recursively_valid?(val)
|
|
52
59
|
end
|
|
53
60
|
true
|
|
@@ -65,10 +72,10 @@ module T::Types
|
|
|
65
72
|
# boundlessness, it does not express a type. For example `(nil...nil)` is not a T::Range[NilClass], its a range
|
|
66
73
|
# of unknown types (T::Range[T.untyped]).
|
|
67
74
|
# Similarly, `(nil...1)` is not a `T::Range[T.nilable(Integer)]`, it's a boundless range of Integer.
|
|
68
|
-
(obj.begin.nil? ||
|
|
75
|
+
(obj.begin.nil? || type.recursively_valid?(obj.begin)) && (obj.end.nil? || type.recursively_valid?(obj.end))
|
|
69
76
|
when Set
|
|
70
77
|
obj.each do |item|
|
|
71
|
-
return false unless
|
|
78
|
+
return false unless type.recursively_valid?(item)
|
|
72
79
|
end
|
|
73
80
|
|
|
74
81
|
true
|
|
@@ -90,7 +97,7 @@ module T::Types
|
|
|
90
97
|
# should be invariant because they are mutable and support
|
|
91
98
|
# both reading and writing. However, Sorbet treats *all*
|
|
92
99
|
# Enumerable subclasses as covariant for ease of adoption.
|
|
93
|
-
|
|
100
|
+
type.subtype_of?(other.type)
|
|
94
101
|
elsif other.class <= Simple
|
|
95
102
|
underlying_class <= other.raw_type
|
|
96
103
|
else
|
|
@@ -3,15 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
module T::Types
|
|
5
5
|
class TypedEnumerator < TypedEnumerable
|
|
6
|
-
attr_reader :type
|
|
7
|
-
|
|
8
6
|
def underlying_class
|
|
9
7
|
Enumerator
|
|
10
8
|
end
|
|
11
9
|
|
|
12
10
|
# overrides Base
|
|
13
11
|
def name
|
|
14
|
-
"T::Enumerator[#{
|
|
12
|
+
"T::Enumerator[#{type.name}]"
|
|
15
13
|
end
|
|
16
14
|
|
|
17
15
|
# overrides Base
|
|
@@ -3,15 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
module T::Types
|
|
5
5
|
class TypedEnumeratorChain < TypedEnumerable
|
|
6
|
-
attr_reader :type
|
|
7
|
-
|
|
8
6
|
def underlying_class
|
|
9
7
|
Enumerator::Chain
|
|
10
8
|
end
|
|
11
9
|
|
|
12
10
|
# overrides Base
|
|
13
11
|
def name
|
|
14
|
-
"T::Enumerator::Chain[#{
|
|
12
|
+
"T::Enumerator::Chain[#{type.name}]"
|
|
15
13
|
end
|
|
16
14
|
|
|
17
15
|
# overrides Base
|
|
@@ -3,15 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
module T::Types
|
|
5
5
|
class TypedEnumeratorLazy < TypedEnumerable
|
|
6
|
-
attr_reader :type
|
|
7
|
-
|
|
8
6
|
def underlying_class
|
|
9
7
|
Enumerator::Lazy
|
|
10
8
|
end
|
|
11
9
|
|
|
12
10
|
# overrides Base
|
|
13
11
|
def name
|
|
14
|
-
"T::Enumerator::Lazy[#{
|
|
12
|
+
"T::Enumerator::Lazy[#{type.name}]"
|
|
15
13
|
end
|
|
16
14
|
|
|
17
15
|
# overrides Base
|
|
@@ -3,22 +3,38 @@
|
|
|
3
3
|
|
|
4
4
|
module T::Types
|
|
5
5
|
class TypedHash < TypedEnumerable
|
|
6
|
-
# Technically we don't need these, but they are a nice api
|
|
7
|
-
attr_reader :keys, :values
|
|
8
|
-
|
|
9
6
|
def underlying_class
|
|
10
7
|
Hash
|
|
11
8
|
end
|
|
12
9
|
|
|
13
10
|
def initialize(keys:, values:)
|
|
14
|
-
@
|
|
15
|
-
@
|
|
16
|
-
|
|
11
|
+
@inner_keys = keys
|
|
12
|
+
@inner_values = values
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Technically we don't need this, but it is a nice api
|
|
16
|
+
def keys
|
|
17
|
+
@keys ||= T::Utils.coerce(@inner_keys)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Technically we don't need this, but it is a nice api
|
|
21
|
+
def values
|
|
22
|
+
@values ||= T::Utils.coerce(@inner_values)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def type
|
|
26
|
+
@type ||= T::Utils.coerce([keys, values])
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def build_type
|
|
30
|
+
keys
|
|
31
|
+
values
|
|
32
|
+
super
|
|
17
33
|
end
|
|
18
34
|
|
|
19
35
|
# overrides Base
|
|
20
36
|
def name
|
|
21
|
-
"T::Hash[#{
|
|
37
|
+
"T::Hash[#{keys.name}, #{values.name}]"
|
|
22
38
|
end
|
|
23
39
|
|
|
24
40
|
# overrides Base
|
data/lib/types/types/union.rb
CHANGED
|
@@ -4,12 +4,14 @@
|
|
|
4
4
|
module T::Types
|
|
5
5
|
# Takes a list of types. Validates that an object matches at least one of the types.
|
|
6
6
|
class Union < Base
|
|
7
|
-
attr_reader :types
|
|
8
|
-
|
|
9
7
|
# Don't use Union.new directly, use `Private::Pool.union_of_types`
|
|
10
8
|
# inside sorbet-runtime and `T.any` elsewhere.
|
|
11
9
|
def initialize(types)
|
|
12
|
-
@
|
|
10
|
+
@inner_types = types
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def types
|
|
14
|
+
@types ||= @inner_types.flat_map do |type|
|
|
13
15
|
type = T::Utils.coerce(type)
|
|
14
16
|
if type.is_a?(Union)
|
|
15
17
|
# Simplify nested unions (mostly so `name` returns a nicer value)
|
|
@@ -20,6 +22,11 @@ module T::Types
|
|
|
20
22
|
end.uniq
|
|
21
23
|
end
|
|
22
24
|
|
|
25
|
+
def build_type
|
|
26
|
+
types
|
|
27
|
+
nil
|
|
28
|
+
end
|
|
29
|
+
|
|
23
30
|
# overrides Base
|
|
24
31
|
def name
|
|
25
32
|
# Use the attr_reader here so we can override it in SimplePairUnion
|
|
@@ -51,12 +58,12 @@ module T::Types
|
|
|
51
58
|
|
|
52
59
|
# overrides Base
|
|
53
60
|
def recursively_valid?(obj)
|
|
54
|
-
|
|
61
|
+
types.any? {|type| type.recursively_valid?(obj)}
|
|
55
62
|
end
|
|
56
63
|
|
|
57
64
|
# overrides Base
|
|
58
65
|
def valid?(obj)
|
|
59
|
-
|
|
66
|
+
types.any? {|type| type.valid?(obj)}
|
|
60
67
|
end
|
|
61
68
|
|
|
62
69
|
# overrides Base
|
data/lib/types/types/untyped.rb
CHANGED
data/lib/types/utils.rb
CHANGED
|
@@ -79,8 +79,8 @@ module T::Utils
|
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
# Unwraps all the sigs.
|
|
82
|
-
def self.run_all_sig_blocks
|
|
83
|
-
T::Private::Methods.run_all_sig_blocks
|
|
82
|
+
def self.run_all_sig_blocks(force_type_init: true)
|
|
83
|
+
T::Private::Methods.run_all_sig_blocks(force_type_init: force_type_init)
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
# Return the underlying type for a type alias. Otherwise returns type.
|
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.5.
|
|
4
|
+
version: 0.5.11175
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stripe
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-01-
|
|
11
|
+
date: 2024-01-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|