sorbet-runtime 0.4.4539 → 0.4.4540
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/types/_types.rb +25 -5
- data/lib/types/types/typed_array.rb +14 -0
- data/lib/types/types/typed_enumerable.rb +16 -1
- data/lib/types/types/typed_enumerator.rb +14 -0
- data/lib/types/types/typed_hash.rb +15 -1
- data/lib/types/types/typed_range.rb +4 -0
- data/lib/types/types/typed_set.rb +14 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e535aeae3d09b4eef7e8983cbf09bee31b71f7f8
|
4
|
+
data.tar.gz: c7587b913aaa915a93ea5c7be6d794c8aa4b0767
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce2ed81c05e056e5acb111546ac2a20ca3abdcbe956e5cba1ec620b639ab71d90cfd331f0ace0ffa009d0b987df3b2550964821c9a66404b0830a42af31d4404
|
7
|
+
data.tar.gz: d798d11d8dc4b6123afe2e043f0b1ce468a6cc660e50c1a5dfab75a40e5104c0f785d18a63e1cbaac0562848d599349730171fba1a8dfd0c545751a4382c2b36
|
data/lib/types/_types.rb
CHANGED
@@ -217,25 +217,41 @@ module T
|
|
217
217
|
|
218
218
|
module Array
|
219
219
|
def self.[](type)
|
220
|
-
T::Types::
|
220
|
+
if type.is_a?(T::Types::Untyped)
|
221
|
+
T::Types::TypedArray::Untyped.new
|
222
|
+
else
|
223
|
+
T::Types::TypedArray.new(type)
|
224
|
+
end
|
221
225
|
end
|
222
226
|
end
|
223
227
|
|
224
228
|
module Hash
|
225
229
|
def self.[](keys, values)
|
226
|
-
T::Types::
|
230
|
+
if keys.is_a?(T::Types::Untyped) && values.is_a?(T::Types::Untyped)
|
231
|
+
T::Types::TypedHash::Untyped.new
|
232
|
+
else
|
233
|
+
T::Types::TypedHash.new(keys: keys, values: values)
|
234
|
+
end
|
227
235
|
end
|
228
236
|
end
|
229
237
|
|
230
238
|
module Enumerable
|
231
239
|
def self.[](type)
|
232
|
-
T::Types::
|
240
|
+
if type.is_a?(T::Types::Untyped)
|
241
|
+
T::Types::TypedEnumerable::Untyped.new
|
242
|
+
else
|
243
|
+
T::Types::TypedEnumerable.new(type)
|
244
|
+
end
|
233
245
|
end
|
234
246
|
end
|
235
247
|
|
236
248
|
module Enumerator
|
237
249
|
def self.[](type)
|
238
|
-
T::Types::
|
250
|
+
if type.is_a?(T::Types::Untyped)
|
251
|
+
T::Types::TypedEnumerator::Untyped.new
|
252
|
+
else
|
253
|
+
T::Types::TypedEnumerator.new(type)
|
254
|
+
end
|
239
255
|
end
|
240
256
|
end
|
241
257
|
|
@@ -247,7 +263,11 @@ module T
|
|
247
263
|
|
248
264
|
module Set
|
249
265
|
def self.[](type)
|
250
|
-
T::Types::
|
266
|
+
if type.is_a?(T::Types::Untyped)
|
267
|
+
T::Types::TypedSet::Untyped.new
|
268
|
+
else
|
269
|
+
T::Types::TypedSet.new(type)
|
270
|
+
end
|
251
271
|
end
|
252
272
|
end
|
253
273
|
|
@@ -8,6 +8,10 @@ module T::Types
|
|
8
8
|
"T::Array[#{@type.name}]"
|
9
9
|
end
|
10
10
|
|
11
|
+
def underlying_class
|
12
|
+
Array
|
13
|
+
end
|
14
|
+
|
11
15
|
# @override Base
|
12
16
|
def valid?(obj)
|
13
17
|
obj.is_a?(Array) && super
|
@@ -16,5 +20,15 @@ module T::Types
|
|
16
20
|
def new(*args) # rubocop:disable PrisonGuard/BanBuiltinMethodOverride
|
17
21
|
Array.new(*T.unsafe(args))
|
18
22
|
end
|
23
|
+
|
24
|
+
class Untyped < TypedArray
|
25
|
+
def initialize
|
26
|
+
super(T.untyped)
|
27
|
+
end
|
28
|
+
|
29
|
+
def valid?(obj)
|
30
|
+
obj.is_a?(Array)
|
31
|
+
end
|
32
|
+
end
|
19
33
|
end
|
20
34
|
end
|
@@ -12,6 +12,10 @@ module T::Types
|
|
12
12
|
@type = T::Utils.coerce(type)
|
13
13
|
end
|
14
14
|
|
15
|
+
def underlying_class
|
16
|
+
Enumerable
|
17
|
+
end
|
18
|
+
|
15
19
|
# @override Base
|
16
20
|
def name
|
17
21
|
"T::Enumerable[#{@type.name}]"
|
@@ -68,7 +72,8 @@ module T::Types
|
|
68
72
|
|
69
73
|
# @override Base
|
70
74
|
private def subtype_of_single?(other)
|
71
|
-
if
|
75
|
+
if other.class <= TypedEnumerable &&
|
76
|
+
underlying_class <= other.underlying_class
|
72
77
|
# Enumerables are covariant because they are read only
|
73
78
|
#
|
74
79
|
# Properly speaking, many Enumerable subtypes (e.g. Set)
|
@@ -137,5 +142,15 @@ module T::Types
|
|
137
142
|
self.class.new(type_from_instances(obj))
|
138
143
|
end
|
139
144
|
end
|
145
|
+
|
146
|
+
class Untyped < TypedEnumerable
|
147
|
+
def initialize
|
148
|
+
super(T.untyped)
|
149
|
+
end
|
150
|
+
|
151
|
+
def valid?(obj)
|
152
|
+
obj.is_a?(Enumerable)
|
153
|
+
end
|
154
|
+
end
|
140
155
|
end
|
141
156
|
end
|
@@ -5,6 +5,10 @@ module T::Types
|
|
5
5
|
class TypedEnumerator < TypedEnumerable
|
6
6
|
attr_reader :type
|
7
7
|
|
8
|
+
def underlying_class
|
9
|
+
Enumerator
|
10
|
+
end
|
11
|
+
|
8
12
|
# @override Base
|
9
13
|
def name
|
10
14
|
"T::Enumerator[#{@type.name}]"
|
@@ -18,5 +22,15 @@ module T::Types
|
|
18
22
|
def new(*args, &blk) # rubocop:disable PrisonGuard/BanBuiltinMethodOverride
|
19
23
|
T.unsafe(Enumerator).new(*args, &blk)
|
20
24
|
end
|
25
|
+
|
26
|
+
class Untyped < TypedEnumerator
|
27
|
+
def initialize
|
28
|
+
super(T.untyped)
|
29
|
+
end
|
30
|
+
|
31
|
+
def valid?(obj)
|
32
|
+
obj.is_a?(Enumerator)
|
33
|
+
end
|
34
|
+
end
|
21
35
|
end
|
22
36
|
end
|
@@ -6,7 +6,11 @@ module T::Types
|
|
6
6
|
# Technically we don't need these, but they are a nice api
|
7
7
|
attr_reader :keys, :values
|
8
8
|
|
9
|
-
def
|
9
|
+
def underlying_class
|
10
|
+
Hash
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(keys:, values:)
|
10
14
|
@keys = T::Utils.coerce(keys)
|
11
15
|
@values = T::Utils.coerce(values)
|
12
16
|
@type = T::Utils.coerce([keys, values])
|
@@ -25,5 +29,15 @@ module T::Types
|
|
25
29
|
def new(*args, &blk) # rubocop:disable PrisonGuard/BanBuiltinMethodOverride
|
26
30
|
Hash.new(*T.unsafe(args), &blk) # rubocop:disable PrisonGuard/RestrictHashDefaults
|
27
31
|
end
|
32
|
+
|
33
|
+
class Untyped < TypedHash
|
34
|
+
def initialize
|
35
|
+
super(keys: T.untyped, values: T.untyped)
|
36
|
+
end
|
37
|
+
|
38
|
+
def valid?(obj)
|
39
|
+
obj.is_a?(Hash)
|
40
|
+
end
|
41
|
+
end
|
28
42
|
end
|
29
43
|
end
|
@@ -5,6 +5,10 @@ module T::Types
|
|
5
5
|
class TypedSet < TypedEnumerable
|
6
6
|
attr_reader :type
|
7
7
|
|
8
|
+
def underlying_class
|
9
|
+
Hash
|
10
|
+
end
|
11
|
+
|
8
12
|
# @override Base
|
9
13
|
def name
|
10
14
|
"T::Set[#{@type.name}]"
|
@@ -18,5 +22,15 @@ module T::Types
|
|
18
22
|
def new(*args) # rubocop:disable PrisonGuard/BanBuiltinMethodOverride
|
19
23
|
Set.new(*T.unsafe(args))
|
20
24
|
end
|
25
|
+
|
26
|
+
class Untyped < TypedSet
|
27
|
+
def initialize
|
28
|
+
super(T.untyped)
|
29
|
+
end
|
30
|
+
|
31
|
+
def valid?(obj)
|
32
|
+
obj.is_a?(Set)
|
33
|
+
end
|
34
|
+
end
|
21
35
|
end
|
22
36
|
end
|