sorbet-runtime 0.5.9090 → 0.5.9094
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 +0 -2
- data/lib/types/configuration.rb +3 -3
- data/lib/types/enum.rb +1 -6
- data/lib/types/private/methods/_methods.rb +2 -2
- data/lib/types/private/methods/modes.rb +18 -6
- data/lib/types/private/methods/signature_validation.rb +0 -1
- data/lib/types/props/_props.rb +15 -5
- data/lib/types/props/decorator.rb +9 -3
- data/lib/types/props/generated_code_validation.rb +1 -1
- data/lib/types/props/optional.rb +3 -3
- data/lib/types/props/private/serializer_generator.rb +0 -1
- data/lib/types/props/serializable.rb +15 -12
- data/lib/types/types/self_type.rb +3 -3
- 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: e859eaf83811425c6f649cb910886787eb966a2ed969dc8c488b96b9064f232f
|
4
|
+
data.tar.gz: 51c973da0682e4952da3d9cfe4b4643594573bb5d0728451ee8ffb7d5cf6a664
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f30d0812326d1835cbbf3ba92f2e3e5971a6b4b4b1ec4d16889e02fe33fbb197d5a307a657d279ac5cb226484cce22140b81815b37226c244bff87e4cf688e76
|
7
|
+
data.tar.gz: a51818555539bf69da1ef2e2bfdb7d71d23e04fc4466e5fcd0574936da07683e81bd63832459d8b263cb2f15362c371ee493242ab93b1d2aa2407c79b764025d
|
data/lib/types/_types.rb
CHANGED
@@ -78,10 +78,8 @@ module T
|
|
78
78
|
T::Types::ClassOf.new(klass)
|
79
79
|
end
|
80
80
|
|
81
|
-
|
82
81
|
## END OF THE METHODS TO PASS TO `sig`.
|
83
82
|
|
84
|
-
|
85
83
|
# Constructs a type alias. Used to create a short name for a larger type. In Ruby this returns a
|
86
84
|
# wrapper that contains a proc that is evaluated to get the underlying type. This syntax however
|
87
85
|
# is needed for support by the static checker. Example usage:
|
data/lib/types/configuration.rb
CHANGED
@@ -429,10 +429,10 @@ module T::Configuration
|
|
429
429
|
MODULE_NAME = Module.instance_method(:name)
|
430
430
|
private_constant :MODULE_NAME
|
431
431
|
|
432
|
-
if T::Configuration::AT_LEAST_RUBY_2_7
|
433
|
-
|
432
|
+
@default_module_name_mangler = if T::Configuration::AT_LEAST_RUBY_2_7
|
433
|
+
->(type) {MODULE_NAME.bind_call(type)}
|
434
434
|
else
|
435
|
-
|
435
|
+
->(type) {MODULE_NAME.bind(type).call}
|
436
436
|
end
|
437
437
|
|
438
438
|
@module_name_mangler = nil
|
data/lib/types/enum.rb
CHANGED
@@ -134,10 +134,8 @@ class T::Enum
|
|
134
134
|
self.from_serialized(mongo_value)
|
135
135
|
end
|
136
136
|
|
137
|
-
|
138
137
|
## Enum instance methods ##
|
139
138
|
|
140
|
-
|
141
139
|
sig {returns(T.self_type)}
|
142
140
|
def dup
|
143
141
|
self
|
@@ -180,7 +178,6 @@ class T::Enum
|
|
180
178
|
end
|
181
179
|
end
|
182
180
|
|
183
|
-
|
184
181
|
# NB: Do not call this method. This exists to allow for a safe migration path in places where enum
|
185
182
|
# values are compared directly against string values.
|
186
183
|
#
|
@@ -246,10 +243,8 @@ class T::Enum
|
|
246
243
|
)
|
247
244
|
end
|
248
245
|
|
249
|
-
|
250
246
|
## Private implementation ##
|
251
247
|
|
252
|
-
|
253
248
|
sig {params(serialized_val: SerializedVal).void}
|
254
249
|
def initialize(serialized_val=nil)
|
255
250
|
raise 'T::Enum is abstract' if self.class == T::Enum
|
@@ -366,6 +361,6 @@ class T::Enum
|
|
366
361
|
|
367
362
|
sig {params(args: String).returns(T.attached_class)}
|
368
363
|
def self._load(args)
|
369
|
-
deserialize(Marshal.load(args))
|
364
|
+
deserialize(Marshal.load(args)) # rubocop:disable Security/MarshalLoad
|
370
365
|
end
|
371
366
|
end
|
@@ -20,7 +20,7 @@ module T::Private::Methods
|
|
20
20
|
# twice is permitted). we could do this with two tables, but it seems slightly
|
21
21
|
# cleaner with a single table.
|
22
22
|
# Effectively T::Hash[Module, T.nilable(Set))]
|
23
|
-
@modules_with_final = Hash.new {
|
23
|
+
@modules_with_final = Hash.new {|hash, key| hash[key] = nil}
|
24
24
|
# this stores the old [included, extended] hooks for Module and inherited hook for Class that we override when
|
25
25
|
# enabling final checks for when those hooks are called. the 'hooks' here don't have anything to do with the 'hooks'
|
26
26
|
# in installed_hooks.
|
@@ -158,7 +158,7 @@ module T::Private::Methods
|
|
158
158
|
|
159
159
|
definition_file, definition_line = T::Private::Methods.signature_for_method(ancestor.instance_method(method_name)).method.source_location
|
160
160
|
is_redefined = target == ancestor
|
161
|
-
caller_loc = caller_locations&.find {|l| !l.to_s.match?(%r{sorbet-runtime[^/]*/lib/})
|
161
|
+
caller_loc = caller_locations&.find {|l| !l.to_s.match?(%r{sorbet-runtime[^/]*/lib/})}
|
162
162
|
extra_info = "\n"
|
163
163
|
if caller_loc
|
164
164
|
extra_info = (is_redefined ? "Redefined" : "Overridden") + " here: #{caller_loc.path}:#{caller_loc.lineno}\n"
|
@@ -2,12 +2,24 @@
|
|
2
2
|
# typed: true
|
3
3
|
|
4
4
|
module T::Private::Methods::Modes
|
5
|
-
def self.standard
|
6
|
-
|
7
|
-
|
8
|
-
def self.
|
9
|
-
|
10
|
-
|
5
|
+
def self.standard
|
6
|
+
'standard'
|
7
|
+
end
|
8
|
+
def self.abstract
|
9
|
+
'abstract'
|
10
|
+
end
|
11
|
+
def self.overridable
|
12
|
+
'overridable'
|
13
|
+
end
|
14
|
+
def self.override
|
15
|
+
'override'
|
16
|
+
end
|
17
|
+
def self.overridable_override
|
18
|
+
'overridable_override'
|
19
|
+
end
|
20
|
+
def self.untyped
|
21
|
+
'untyped'
|
22
|
+
end
|
11
23
|
MODES = [self.standard, self.abstract, self.overridable, self.override, self.overridable_override, self.untyped].freeze
|
12
24
|
|
13
25
|
OVERRIDABLE_MODES = [self.override, self.overridable, self.overridable_override, self.untyped, self.abstract].freeze
|
@@ -154,7 +154,6 @@ module T::Private::Methods::SignatureValidation
|
|
154
154
|
"#{base_override_loc_str(signature, super_signature)}"
|
155
155
|
end
|
156
156
|
|
157
|
-
|
158
157
|
# O(nm), but n and m are tiny here
|
159
158
|
extra_req_kwargs = signature.req_kwarg_names - super_signature.req_kwarg_names
|
160
159
|
if !extra_req_kwargs.empty?
|
data/lib/types/props/_props.rb
CHANGED
@@ -20,13 +20,23 @@ module T::Props
|
|
20
20
|
extend T::Sig
|
21
21
|
extend T::Helpers
|
22
22
|
|
23
|
-
def props
|
24
|
-
|
23
|
+
def props
|
24
|
+
decorator.props
|
25
|
+
end
|
26
|
+
def plugins
|
27
|
+
@plugins ||= []
|
28
|
+
end
|
25
29
|
|
26
|
-
def decorator_class
|
30
|
+
def decorator_class
|
31
|
+
Decorator
|
32
|
+
end
|
27
33
|
|
28
|
-
def decorator
|
29
|
-
|
34
|
+
def decorator
|
35
|
+
@decorator ||= decorator_class.new(self)
|
36
|
+
end
|
37
|
+
def reload_decorator!
|
38
|
+
@decorator = decorator_class.new(self)
|
39
|
+
end
|
30
40
|
|
31
41
|
# @!method self.prop(name, type, opts={})
|
32
42
|
#
|
@@ -34,11 +34,15 @@ class T::Props::Decorator
|
|
34
34
|
attr_reader :props
|
35
35
|
|
36
36
|
sig {returns(T::Array[Symbol])}
|
37
|
-
def all_props
|
37
|
+
def all_props
|
38
|
+
props.keys
|
39
|
+
end
|
38
40
|
|
39
41
|
# checked(:never) - O(prop accesses)
|
40
42
|
sig {params(prop: T.any(Symbol, String)).returns(Rules).checked(:never)}
|
41
|
-
def prop_rules(prop)
|
43
|
+
def prop_rules(prop)
|
44
|
+
props[prop.to_sym] || raise("No such prop: #{prop.inspect}")
|
45
|
+
end
|
42
46
|
|
43
47
|
# checked(:never) - Rules hash is expensive to check
|
44
48
|
sig {params(prop: Symbol, rules: Rules).void.checked(:never)}
|
@@ -78,7 +82,9 @@ class T::Props::Decorator
|
|
78
82
|
|
79
83
|
# checked(:never) - O(prop accesses)
|
80
84
|
sig {returns(T.all(Module, T::Props::ClassMethods)).checked(:never)}
|
81
|
-
def decorated_class
|
85
|
+
def decorated_class
|
86
|
+
@class
|
87
|
+
end
|
82
88
|
|
83
89
|
# Accessors
|
84
90
|
|
@@ -157,7 +157,7 @@ module T::Props
|
|
157
157
|
validate_lack_of_side_effects(try, whitelisted_methods_for_deserialize)
|
158
158
|
|
159
159
|
assert_equal(:resbody, rescue_body.type)
|
160
|
-
exceptions, assignment, handler =
|
160
|
+
exceptions, assignment, handler = rescue_body.children
|
161
161
|
assert_equal(:array, exceptions.type)
|
162
162
|
exceptions.children.each {|c| assert_equal(:const, c.type)}
|
163
163
|
assert_equal(:lvasgn, assignment.type)
|
data/lib/types/props/optional.rb
CHANGED
@@ -5,10 +5,8 @@ module T::Props::Optional
|
|
5
5
|
include T::Props::Plugin
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
8
|
##############################################
|
10
9
|
|
11
|
-
|
12
10
|
# NB: This must stay in the same file where T::Props::Optional is defined due to
|
13
11
|
# T::Props::Decorator#apply_plugin; see https://git.corp.stripe.com/stripe-internal/pay-server/blob/fc7f15593b49875f2d0499ffecfd19798bac05b3/chalk/odm/lib/chalk-odm/document_decorator.rb#L716-L717
|
14
12
|
module T::Props::Optional::DecoratorMethods
|
@@ -27,7 +25,9 @@ module T::Props::Optional::DecoratorMethods
|
|
27
25
|
super || VALID_RULE_KEYS[key]
|
28
26
|
end
|
29
27
|
|
30
|
-
def prop_optional?(prop)
|
28
|
+
def prop_optional?(prop)
|
29
|
+
prop_rules(prop)[:fully_optional]
|
30
|
+
end
|
31
31
|
|
32
32
|
def compute_derived_rules(rules)
|
33
33
|
rules[:fully_optional] = !T::Props::Utils.need_nil_write_check?(rules)
|
@@ -15,7 +15,7 @@ module T::Props::Serializable
|
|
15
15
|
# exception if this object has mandatory props with missing
|
16
16
|
# values.
|
17
17
|
# @return [Hash] A serialization of this object.
|
18
|
-
def serialize(strict=true)
|
18
|
+
def serialize(strict=true)
|
19
19
|
begin
|
20
20
|
h = __t_props_generated_serialize(strict)
|
21
21
|
rescue => e
|
@@ -56,7 +56,7 @@ module T::Props::Serializable
|
|
56
56
|
# the hash contains keys that do not correspond to any known
|
57
57
|
# props on this instance.
|
58
58
|
# @return [void]
|
59
|
-
def deserialize(hash, strict=false)
|
59
|
+
def deserialize(hash, strict=false)
|
60
60
|
begin
|
61
61
|
hash_keys_matching_props = __t_props_generated_deserialize(hash)
|
62
62
|
rescue => e
|
@@ -171,7 +171,6 @@ module T::Props::Serializable
|
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
174
|
-
|
175
174
|
##############################################
|
176
175
|
|
177
176
|
# NB: This must stay in the same file where T::Props::Serializable is defined due to
|
@@ -190,10 +189,14 @@ module T::Props::Serializable::DecoratorMethods
|
|
190
189
|
@class.props.select {|_, v| T::Props::Utils.required_prop?(v)}.keys
|
191
190
|
end
|
192
191
|
|
193
|
-
def prop_dont_store?(prop)
|
194
|
-
|
192
|
+
def prop_dont_store?(prop)
|
193
|
+
prop_rules(prop)[:dont_store]
|
194
|
+
end
|
195
|
+
def prop_by_serialized_forms
|
196
|
+
@class.prop_by_serialized_forms
|
197
|
+
end
|
195
198
|
|
196
|
-
def from_hash(hash, strict=false)
|
199
|
+
def from_hash(hash, strict=false)
|
197
200
|
raise ArgumentError.new("#{hash.inspect} provided to from_hash") if !(hash && hash.is_a?(Hash))
|
198
201
|
|
199
202
|
i = @class.allocate
|
@@ -260,7 +263,7 @@ module T::Props::Serializable::DecoratorMethods
|
|
260
263
|
context = " #{source_lines[(previous_blank + 1)...next_blank].join("\n ")}"
|
261
264
|
<<~MSG
|
262
265
|
Error in #{decorated_class.name}##{generated_method}: #{error.message}
|
263
|
-
at line #{line_num-previous_blank-1} in:
|
266
|
+
at line #{line_num - previous_blank - 1} in:
|
264
267
|
#{context}
|
265
268
|
MSG
|
266
269
|
end
|
@@ -300,7 +303,7 @@ module T::Props::Serializable::DecoratorMethods
|
|
300
303
|
end
|
301
304
|
|
302
305
|
if !rules[:raise_on_nil_write].nil? && rules[:raise_on_nil_write] != true
|
303
|
-
|
306
|
+
raise ArgumentError.new("The value of `raise_on_nil_write` if specified must be `true` (given: #{rules[:raise_on_nil_write]}).")
|
304
307
|
end
|
305
308
|
|
306
309
|
result
|
@@ -334,21 +337,21 @@ module T::Props::Serializable::DecoratorMethods
|
|
334
337
|
end
|
335
338
|
end
|
336
339
|
|
337
|
-
|
338
340
|
##############################################
|
339
341
|
|
340
|
-
|
341
342
|
# NB: This must stay in the same file where T::Props::Serializable is defined due to
|
342
343
|
# T::Props::Decorator#apply_plugin; see https://git.corp.stripe.com/stripe-internal/pay-server/blob/fc7f15593b49875f2d0499ffecfd19798bac05b3/chalk/odm/lib/chalk-odm/document_decorator.rb#L716-L717
|
343
344
|
module T::Props::Serializable::ClassMethods
|
344
|
-
def prop_by_serialized_forms
|
345
|
+
def prop_by_serialized_forms
|
346
|
+
@prop_by_serialized_forms ||= {}
|
347
|
+
end
|
345
348
|
|
346
349
|
# @!method self.from_hash(hash, strict)
|
347
350
|
#
|
348
351
|
# Allocate a new instance and call {#deserialize} to load a new
|
349
352
|
# object from a hash.
|
350
353
|
# @return [Serializable]
|
351
|
-
def from_hash(hash, strict=false)
|
354
|
+
def from_hash(hash, strict=false)
|
352
355
|
self.decorator.from_hash(hash, strict)
|
353
356
|
end
|
354
357
|
|
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.9094
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stripe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|