sorbet-runtime 0.5.5821 → 0.5.5843
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/_types.rb +4 -4
- data/lib/types/profile.rb +5 -1
- data/lib/types/props/constructor.rb +9 -3
- data/lib/types/props/weak_constructor.rb +14 -9
- data/lib/types/types/attached_class.rb +4 -0
- data/lib/types/types/fixed_array.rb +12 -2
- data/lib/types/types/fixed_hash.rb +2 -9
- data/lib/types/types/noreturn.rb +4 -0
- data/lib/types/types/self_type.rb +4 -0
- data/lib/types/types/union.rb +1 -5
- data/lib/types/types/untyped.rb +4 -0
- 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: 4aa66cf13c6570f24fd5c7d394119fd49ce3bb595f85cc2cf2584232d3cb9ff4
|
4
|
+
data.tar.gz: b223ba693cdb5e2795f3adbfab10a7b1fc127457821011b26344510ada3495d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a58a518764c9fb4309a14f9174cf17080e4e5fca191d189c5562a3aad610f0c153e0a334b9ce6ce1aa78cd7906f52336a8795a1a3f1e513ce7c972a934605b33
|
7
|
+
data.tar.gz: 6f638789b8c7cdece2c89b82d7f49687dcc7183b04b5a3be85e655a809b5f97f2a7f8969a34ddf12016d52de5444d882cf50a7dca61df728e32ed8b1855391d1
|
data/lib/types/_types.rb
CHANGED
@@ -37,12 +37,12 @@ module T
|
|
37
37
|
# Matches any object. In the static checker, T.untyped allows any
|
38
38
|
# method calls or operations.
|
39
39
|
def self.untyped
|
40
|
-
T::Types::Untyped
|
40
|
+
T::Types::Untyped::Private::INSTANCE
|
41
41
|
end
|
42
42
|
|
43
43
|
# Indicates a function never returns (e.g. "Kernel#raise")
|
44
44
|
def self.noreturn
|
45
|
-
T::Types::NoReturn
|
45
|
+
T::Types::NoReturn::Private::INSTANCE
|
46
46
|
end
|
47
47
|
|
48
48
|
# T.all(<Type>, <Type>, ...) -- matches an object that has all of the types listed
|
@@ -62,12 +62,12 @@ module T
|
|
62
62
|
|
63
63
|
# Matches `self`:
|
64
64
|
def self.self_type
|
65
|
-
T::Types::SelfType
|
65
|
+
T::Types::SelfType::Private::INSTANCE
|
66
66
|
end
|
67
67
|
|
68
68
|
# Matches the instance type in a singleton-class context
|
69
69
|
def self.attached_class
|
70
|
-
T::Types::AttachedClassType
|
70
|
+
T::Types::AttachedClassType::Private::INSTANCE
|
71
71
|
end
|
72
72
|
|
73
73
|
# Matches any class that subclasses or includes the provided class
|
data/lib/types/profile.rb
CHANGED
@@ -10,7 +10,11 @@ module T::Profile
|
|
10
10
|
def typecheck_duration_estimate
|
11
11
|
total_typechecks = typecheck_samples * SAMPLE_RATE + (SAMPLE_RATE - typecheck_sample_attempts)
|
12
12
|
typechecks_measured = typecheck_samples * SAMPLE_RATE
|
13
|
-
|
13
|
+
if typechecks_measured.positive?
|
14
|
+
typecheck_duration * SAMPLE_RATE * 1.0 * total_typechecks / typechecks_measured
|
15
|
+
else
|
16
|
+
0.0
|
17
|
+
end
|
14
18
|
end
|
15
19
|
|
16
20
|
def typecheck_count_estimate
|
@@ -17,11 +17,16 @@ module T::Props::Constructor::DecoratorMethods
|
|
17
17
|
# checked(:never) - O(runtime object construction)
|
18
18
|
sig {params(instance: T::Props::Constructor, hash: T::Hash[Symbol, T.untyped]).returns(Integer).checked(:never)}
|
19
19
|
def construct_props_without_defaults(instance, hash)
|
20
|
-
|
20
|
+
# Use `each_pair` rather than `count` because, as of Ruby 2.6, the latter delegates to Enumerator
|
21
|
+
# and therefore allocates for each entry.
|
22
|
+
result = 0
|
23
|
+
@props_without_defaults&.each_pair do |p, setter_proc|
|
21
24
|
begin
|
22
25
|
val = hash[p]
|
23
26
|
instance.instance_exec(val, &setter_proc)
|
24
|
-
val || hash.key?(p)
|
27
|
+
if val || hash.key?(p)
|
28
|
+
result += 1
|
29
|
+
end
|
25
30
|
rescue TypeError, T::Props::InvalidValueError
|
26
31
|
if !hash.key?(p)
|
27
32
|
raise ArgumentError.new("Missing required prop `#{p}` for class `#{instance.class.name}`")
|
@@ -29,6 +34,7 @@ module T::Props::Constructor::DecoratorMethods
|
|
29
34
|
raise
|
30
35
|
end
|
31
36
|
end
|
32
|
-
end
|
37
|
+
end
|
38
|
+
result
|
33
39
|
end
|
34
40
|
end
|
@@ -30,14 +30,16 @@ module T::Props::WeakConstructor::DecoratorMethods
|
|
30
30
|
# checked(:never) - O(runtime object construction)
|
31
31
|
sig {params(instance: T::Props::WeakConstructor, hash: T::Hash[Symbol, T.untyped]).returns(Integer).checked(:never)}
|
32
32
|
def construct_props_without_defaults(instance, hash)
|
33
|
-
|
33
|
+
# Use `each_pair` rather than `count` because, as of Ruby 2.6, the latter delegates to Enumerator
|
34
|
+
# and therefore allocates for each entry.
|
35
|
+
result = 0
|
36
|
+
@props_without_defaults&.each_pair do |p, setter_proc|
|
34
37
|
if hash.key?(p)
|
35
38
|
instance.instance_exec(hash[p], &setter_proc)
|
36
|
-
|
37
|
-
else
|
38
|
-
false
|
39
|
+
result += 1
|
39
40
|
end
|
40
|
-
end
|
41
|
+
end
|
42
|
+
result
|
41
43
|
end
|
42
44
|
|
43
45
|
# Set values for all props that have defaults. Use the default if and only if
|
@@ -49,14 +51,17 @@ module T::Props::WeakConstructor::DecoratorMethods
|
|
49
51
|
# checked(:never) - O(runtime object construction)
|
50
52
|
sig {params(instance: T::Props::WeakConstructor, hash: T::Hash[Symbol, T.untyped]).returns(Integer).checked(:never)}
|
51
53
|
def construct_props_with_defaults(instance, hash)
|
52
|
-
|
54
|
+
# Use `each_pair` rather than `count` because, as of Ruby 2.6, the latter delegates to Enumerator
|
55
|
+
# and therefore allocates for each entry.
|
56
|
+
result = 0
|
57
|
+
@props_with_defaults&.each_pair do |p, default_struct|
|
53
58
|
if hash.key?(p)
|
54
59
|
instance.instance_exec(hash[p], &default_struct.setter_proc)
|
55
|
-
|
60
|
+
result += 1
|
56
61
|
else
|
57
62
|
default_struct.set_default(instance)
|
58
|
-
false
|
59
63
|
end
|
60
|
-
end
|
64
|
+
end
|
65
|
+
result
|
61
66
|
end
|
62
67
|
end
|
@@ -19,8 +19,18 @@ module T::Types
|
|
19
19
|
|
20
20
|
# @override Base
|
21
21
|
def valid?(obj)
|
22
|
-
obj.is_a?(Array) && obj.length == @types.length
|
23
|
-
|
22
|
+
if obj.is_a?(Array) && obj.length == @types.length
|
23
|
+
i = 0
|
24
|
+
while i < @types.length
|
25
|
+
if !@types[i].valid?(obj[i])
|
26
|
+
return false
|
27
|
+
end
|
28
|
+
i += 1
|
29
|
+
end
|
30
|
+
true
|
31
|
+
else
|
32
|
+
false
|
33
|
+
end
|
24
34
|
end
|
25
35
|
|
26
36
|
# @override Base
|
@@ -19,15 +19,8 @@ module T::Types
|
|
19
19
|
# @override Base
|
20
20
|
def valid?(obj)
|
21
21
|
return false unless obj.is_a?(Hash)
|
22
|
-
|
23
|
-
|
24
|
-
return false unless type.valid?(obj[key])
|
25
|
-
end
|
26
|
-
|
27
|
-
obj.each_key do |key|
|
28
|
-
return false unless @types[key]
|
29
|
-
end
|
30
|
-
|
22
|
+
return false if @types.any? {|key, type| !type.valid?(obj[key])}
|
23
|
+
return false if obj.any? {|key, _| !@types[key]}
|
31
24
|
true
|
32
25
|
end
|
33
26
|
|
data/lib/types/types/noreturn.rb
CHANGED
data/lib/types/types/union.rb
CHANGED
data/lib/types/types/untyped.rb
CHANGED
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.5843
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stripe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|