sorbet-runtime 0.5.8993 → 0.5.9889
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 +4 -2
- data/lib/types/_types.rb +20 -9
- data/lib/types/configuration.rb +89 -56
- data/lib/types/enum.rb +14 -15
- data/lib/types/generic.rb +4 -2
- data/lib/types/helpers.rb +4 -2
- data/lib/types/interface_wrapper.rb +4 -4
- data/lib/types/non_forcing_constants.rb +5 -9
- data/lib/types/private/abstract/data.rb +1 -1
- data/lib/types/private/abstract/declare.rb +5 -0
- data/lib/types/private/abstract/hooks.rb +1 -2
- data/lib/types/private/casts.rb +2 -10
- data/lib/types/private/class_utils.rb +1 -2
- data/lib/types/private/compiler.rb +24 -0
- data/lib/types/private/methods/_methods.rb +25 -19
- data/lib/types/private/methods/decl_builder.rb +5 -5
- data/lib/types/private/methods/modes.rb +18 -6
- data/lib/types/private/methods/signature.rb +11 -2
- data/lib/types/private/methods/signature_validation.rb +3 -4
- data/lib/types/private/runtime_levels.rb +7 -1
- data/lib/types/private/sealed.rb +27 -16
- data/lib/types/private/types/not_typed.rb +4 -4
- data/lib/types/private/types/string_holder.rb +3 -3
- data/lib/types/private/types/type_alias.rb +3 -3
- data/lib/types/private/types/void.rb +4 -4
- data/lib/types/props/_props.rb +21 -14
- data/lib/types/props/constructor.rb +1 -1
- data/lib/types/props/custom_type.rb +1 -1
- data/lib/types/props/decorator.rb +36 -54
- data/lib/types/props/generated_code_validation.rb +1 -1
- data/lib/types/props/has_lazily_specialized_methods.rb +6 -1
- data/lib/types/props/optional.rb +5 -5
- data/lib/types/props/private/serde_transform.rb +3 -3
- data/lib/types/props/private/serializer_generator.rb +0 -1
- data/lib/types/props/serializable.rb +26 -20
- data/lib/types/props/weak_constructor.rb +2 -2
- data/lib/types/types/attached_class.rb +3 -3
- data/lib/types/types/base.rb +8 -2
- data/lib/types/types/class_of.rb +6 -4
- data/lib/types/types/enum.rb +5 -7
- data/lib/types/types/fixed_array.rb +5 -5
- data/lib/types/types/fixed_hash.rb +23 -17
- data/lib/types/types/intersection.rb +4 -4
- data/lib/types/types/noreturn.rb +3 -3
- data/lib/types/types/proc.rb +3 -3
- data/lib/types/types/self_type.rb +6 -6
- data/lib/types/types/simple.rb +32 -7
- data/lib/types/types/t_enum.rb +3 -3
- data/lib/types/types/typed_array.rb +3 -3
- data/lib/types/types/typed_enumerable.rb +10 -5
- data/lib/types/types/typed_enumerator.rb +3 -3
- data/lib/types/types/typed_enumerator_lazy.rb +41 -0
- data/lib/types/types/typed_hash.rb +3 -3
- data/lib/types/types/typed_range.rb +3 -3
- data/lib/types/types/typed_set.rb +15 -3
- data/lib/types/types/union.rb +4 -4
- data/lib/types/types/untyped.rb +3 -3
- data/lib/types/utils.rb +9 -1
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9a7a3fab5ea8600237fa39e859be1e28620584bb1b58349d049e0f5e03146dc1
|
|
4
|
+
data.tar.gz: 4ae6ef0d6b43dc1205d5a54f141c5a4775eaecacae3b37c1d89dbc32a259d702
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 72c661853dc7f8b7243d7b37cc5868c1bb962df3b6df38b8c5d1f8345751bdea0bb69bc15f5eb5dbb1dde132da4720afe0ee87cf112dcd2e33cbd6264f704ecb
|
|
7
|
+
data.tar.gz: 2d9060c44a422f615c44d1cbc61e24f051f7087c3e18552b5fd702f99649c85eb12276cce7186d2ecf5c2b97f269fe0a503edde775ff94d6d6b2cd9dc1bb781c
|
data/lib/sorbet-runtime.rb
CHANGED
|
@@ -12,8 +12,6 @@ module T::Private; end
|
|
|
12
12
|
module T::Private::Abstract; end
|
|
13
13
|
module T::Private::Types; end
|
|
14
14
|
|
|
15
|
-
require 'set'
|
|
16
|
-
|
|
17
15
|
# Each section is a group that I believe need a fixed ordering. There is also
|
|
18
16
|
# an ordering between groups.
|
|
19
17
|
|
|
@@ -47,6 +45,7 @@ require_relative 'types/types/t_enum'
|
|
|
47
45
|
require_relative 'types/types/type_parameter'
|
|
48
46
|
require_relative 'types/types/typed_array'
|
|
49
47
|
require_relative 'types/types/typed_enumerator'
|
|
48
|
+
require_relative 'types/types/typed_enumerator_lazy'
|
|
50
49
|
require_relative 'types/types/typed_hash'
|
|
51
50
|
require_relative 'types/types/typed_range'
|
|
52
51
|
require_relative 'types/types/typed_set'
|
|
@@ -112,3 +111,6 @@ require_relative 'types/struct'
|
|
|
112
111
|
require_relative 'types/non_forcing_constants'
|
|
113
112
|
|
|
114
113
|
require_relative 'types/compatibility_patches'
|
|
114
|
+
|
|
115
|
+
# Sorbet Compiler support module
|
|
116
|
+
require_relative 'types/private/compiler'
|
data/lib/types/_types.rb
CHANGED
|
@@ -53,7 +53,8 @@ module T
|
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
# Matches any of the listed values
|
|
56
|
-
|
|
56
|
+
# @deprecated Use T::Enum instead.
|
|
57
|
+
def self.deprecated_enum(values)
|
|
57
58
|
T::Types::Enum.new(values)
|
|
58
59
|
end
|
|
59
60
|
|
|
@@ -78,14 +79,13 @@ module T
|
|
|
78
79
|
T::Types::ClassOf.new(klass)
|
|
79
80
|
end
|
|
80
81
|
|
|
81
|
-
|
|
82
82
|
## END OF THE METHODS TO PASS TO `sig`.
|
|
83
83
|
|
|
84
|
-
|
|
85
84
|
# Constructs a type alias. Used to create a short name for a larger type. In Ruby this returns a
|
|
86
85
|
# wrapper that contains a proc that is evaluated to get the underlying type. This syntax however
|
|
87
|
-
# is needed for support by the static checker.
|
|
86
|
+
# is needed for support by the static checker.
|
|
88
87
|
#
|
|
88
|
+
# @example
|
|
89
89
|
# NilableString = T.type_alias {T.nilable(String)}
|
|
90
90
|
#
|
|
91
91
|
# sig {params(arg: NilableString, default: String).returns(String)}
|
|
@@ -108,8 +108,9 @@ module T
|
|
|
108
108
|
# References a type parameter which was previously defined with
|
|
109
109
|
# `type_parameters`.
|
|
110
110
|
#
|
|
111
|
-
# This is used for generic methods.
|
|
111
|
+
# This is used for generic methods.
|
|
112
112
|
#
|
|
113
|
+
# @example
|
|
113
114
|
# sig
|
|
114
115
|
# .type_parameters(:U)
|
|
115
116
|
# .params(
|
|
@@ -187,7 +188,7 @@ module T
|
|
|
187
188
|
# cycle. However, we also don't actually need to do so; An untyped
|
|
188
189
|
# identity method works just as well here.
|
|
189
190
|
#
|
|
190
|
-
# sig {params(value: T.untyped).returns(T.untyped)}
|
|
191
|
+
# `sig {params(value: T.untyped).returns(T.untyped)}`
|
|
191
192
|
def self.unsafe(value)
|
|
192
193
|
value
|
|
193
194
|
end
|
|
@@ -208,7 +209,7 @@ module T
|
|
|
208
209
|
# Intended to be used to promise sorbet that a given nilable value happens
|
|
209
210
|
# to contain a non-nil value at this point.
|
|
210
211
|
#
|
|
211
|
-
# sig {params(arg: T.nilable(A)).returns(A)}
|
|
212
|
+
# `sig {params(arg: T.nilable(A)).returns(A)}`
|
|
212
213
|
def self.must(arg)
|
|
213
214
|
return arg if arg
|
|
214
215
|
return arg if arg == false
|
|
@@ -216,7 +217,7 @@ module T
|
|
|
216
217
|
begin
|
|
217
218
|
raise TypeError.new("Passed `nil` into T.must")
|
|
218
219
|
rescue TypeError => e # raise into rescue to ensure e.backtrace is populated
|
|
219
|
-
T::Configuration.inline_type_error_handler(e)
|
|
220
|
+
T::Configuration.inline_type_error_handler(e, {kind: 'T.must', value: arg, type: nil})
|
|
220
221
|
end
|
|
221
222
|
end
|
|
222
223
|
|
|
@@ -241,7 +242,7 @@ module T
|
|
|
241
242
|
begin
|
|
242
243
|
raise TypeError.new(msg)
|
|
243
244
|
rescue TypeError => e # raise into rescue to ensure e.backtrace is populated
|
|
244
|
-
T::Configuration.inline_type_error_handler(e)
|
|
245
|
+
T::Configuration.inline_type_error_handler(e, {kind: 'T.absurd', value: value, type: nil})
|
|
245
246
|
end
|
|
246
247
|
end
|
|
247
248
|
|
|
@@ -285,6 +286,16 @@ module T
|
|
|
285
286
|
T::Types::TypedEnumerator.new(type)
|
|
286
287
|
end
|
|
287
288
|
end
|
|
289
|
+
|
|
290
|
+
module Lazy
|
|
291
|
+
def self.[](type)
|
|
292
|
+
if type.is_a?(T::Types::Untyped)
|
|
293
|
+
T::Types::TypedEnumeratorLazy::Untyped.new
|
|
294
|
+
else
|
|
295
|
+
T::Types::TypedEnumeratorLazy.new(type)
|
|
296
|
+
end
|
|
297
|
+
end
|
|
298
|
+
end
|
|
288
299
|
end
|
|
289
300
|
|
|
290
301
|
module Range
|
data/lib/types/configuration.rb
CHANGED
|
@@ -80,6 +80,7 @@ module T::Configuration
|
|
|
80
80
|
T::Props::Private::DeserializerGenerator.respond_to?(:generate2)
|
|
81
81
|
end
|
|
82
82
|
|
|
83
|
+
@use_vm_prop_serde = false
|
|
83
84
|
# Whether to use VM-defined prop serialization/deserialization routines.
|
|
84
85
|
#
|
|
85
86
|
# The default is to use runtime codegen inside sorbet-runtime itself.
|
|
@@ -112,11 +113,12 @@ module T::Configuration
|
|
|
112
113
|
# statically, so that methods don't have to guard themselves from being
|
|
113
114
|
# called incorrectly by untyped code.
|
|
114
115
|
#
|
|
115
|
-
# @param [:never, :tests, :always] default_checked_level
|
|
116
|
+
# @param [:never, :compiled, :tests, :always] default_checked_level
|
|
116
117
|
def self.default_checked_level=(default_checked_level)
|
|
117
118
|
T::Private::RuntimeLevels.default_checked_level = default_checked_level
|
|
118
119
|
end
|
|
119
120
|
|
|
121
|
+
@inline_type_error_handler = nil
|
|
120
122
|
# Set a handler to handle `TypeError`s raised by any in-line type assertions,
|
|
121
123
|
# including `T.must`, `T.let`, `T.cast`, and `T.assert_type!`.
|
|
122
124
|
#
|
|
@@ -130,10 +132,15 @@ module T::Configuration
|
|
|
130
132
|
#
|
|
131
133
|
# Parameters passed to value.call:
|
|
132
134
|
#
|
|
133
|
-
#
|
|
135
|
+
# @param [TypeError] error TypeError that was raised
|
|
136
|
+
# @param [Hash] opts A hash containing contextual information on the error:
|
|
137
|
+
# @option opts [String] :kind One of:
|
|
138
|
+
# ['T.cast', 'T.let', 'T.bind', 'T.assert_type!', 'T.must', 'T.absurd']
|
|
139
|
+
# @option opts [Object, nil] :type Expected param/return value type
|
|
140
|
+
# @option opts [Object] :value Actual param/return value
|
|
134
141
|
#
|
|
135
142
|
# @example
|
|
136
|
-
# T::Configuration.inline_type_error_handler = lambda do |error|
|
|
143
|
+
# T::Configuration.inline_type_error_handler = lambda do |error, opts|
|
|
137
144
|
# puts error.message
|
|
138
145
|
# end
|
|
139
146
|
def self.inline_type_error_handler=(value)
|
|
@@ -141,19 +148,25 @@ module T::Configuration
|
|
|
141
148
|
@inline_type_error_handler = value
|
|
142
149
|
end
|
|
143
150
|
|
|
144
|
-
private_class_method def self.inline_type_error_handler_default(error)
|
|
151
|
+
private_class_method def self.inline_type_error_handler_default(error, opts)
|
|
145
152
|
raise error
|
|
146
153
|
end
|
|
147
154
|
|
|
148
|
-
def self.inline_type_error_handler(error)
|
|
155
|
+
def self.inline_type_error_handler(error, opts={})
|
|
149
156
|
if @inline_type_error_handler
|
|
150
|
-
|
|
157
|
+
# Backwards compatibility before `inline_type_error_handler` took a second arg
|
|
158
|
+
if @inline_type_error_handler.arity == 1
|
|
159
|
+
@inline_type_error_handler.call(error)
|
|
160
|
+
else
|
|
161
|
+
@inline_type_error_handler.call(error, opts)
|
|
162
|
+
end
|
|
151
163
|
else
|
|
152
|
-
inline_type_error_handler_default(error)
|
|
164
|
+
inline_type_error_handler_default(error, opts)
|
|
153
165
|
end
|
|
154
166
|
nil
|
|
155
167
|
end
|
|
156
168
|
|
|
169
|
+
@sig_builder_error_handler = nil
|
|
157
170
|
# Set a handler to handle errors that occur when the builder methods in the
|
|
158
171
|
# body of a sig are executed. The sig builder methods are inside a proc so
|
|
159
172
|
# that they can be lazily evaluated the first time the method being sig'd is
|
|
@@ -169,8 +182,8 @@ module T::Configuration
|
|
|
169
182
|
#
|
|
170
183
|
# Parameters passed to value.call:
|
|
171
184
|
#
|
|
172
|
-
#
|
|
173
|
-
#
|
|
185
|
+
# @param [StandardError] error The error that was raised
|
|
186
|
+
# @param [Thread::Backtrace::Location] location Location of the error
|
|
174
187
|
#
|
|
175
188
|
# @example
|
|
176
189
|
# T::Configuration.sig_builder_error_handler = lambda do |error, location|
|
|
@@ -194,6 +207,7 @@ module T::Configuration
|
|
|
194
207
|
nil
|
|
195
208
|
end
|
|
196
209
|
|
|
210
|
+
@sig_validation_error_handler = nil
|
|
197
211
|
# Set a handler to handle sig validation errors.
|
|
198
212
|
#
|
|
199
213
|
# Sig validation errors include things like abstract checks, override checks,
|
|
@@ -211,16 +225,16 @@ module T::Configuration
|
|
|
211
225
|
#
|
|
212
226
|
# Parameters passed to value.call:
|
|
213
227
|
#
|
|
214
|
-
#
|
|
215
|
-
#
|
|
216
|
-
#
|
|
217
|
-
#
|
|
218
|
-
#
|
|
219
|
-
#
|
|
220
|
-
#
|
|
221
|
-
#
|
|
222
|
-
#
|
|
223
|
-
#
|
|
228
|
+
# @param [StandardError] error The error that was raised
|
|
229
|
+
# @param [Hash] opts A hash containing contextual information on the error:
|
|
230
|
+
# @option opts [Method, UnboundMethod] :method Method on which the signature build failed
|
|
231
|
+
# @option opts [T::Private::Methods::Declaration] :declaration Method
|
|
232
|
+
# signature declaration struct
|
|
233
|
+
# @option opts [T::Private::Methods::Signature, nil] :signature Signature
|
|
234
|
+
# that failed (nil if sig build failed before Signature initialization)
|
|
235
|
+
# @option opts [T::Private::Methods::Signature, nil] :super_signature Super
|
|
236
|
+
# method's signature (nil if method is not an override or super method
|
|
237
|
+
# does not have a method signature)
|
|
224
238
|
#
|
|
225
239
|
# @example
|
|
226
240
|
# T::Configuration.sig_validation_error_handler = lambda do |error, opts|
|
|
@@ -244,6 +258,7 @@ module T::Configuration
|
|
|
244
258
|
nil
|
|
245
259
|
end
|
|
246
260
|
|
|
261
|
+
@call_validation_error_handler = nil
|
|
247
262
|
# Set a handler for type errors that result from calling a method.
|
|
248
263
|
#
|
|
249
264
|
# By default, errors from calling a method cause an exception to be raised.
|
|
@@ -256,17 +271,17 @@ module T::Configuration
|
|
|
256
271
|
#
|
|
257
272
|
# Parameters passed to value.call:
|
|
258
273
|
#
|
|
259
|
-
#
|
|
260
|
-
#
|
|
261
|
-
#
|
|
262
|
-
#
|
|
263
|
-
#
|
|
264
|
-
#
|
|
265
|
-
#
|
|
266
|
-
#
|
|
267
|
-
#
|
|
268
|
-
#
|
|
269
|
-
#
|
|
274
|
+
# @param [T::Private::Methods::Signature] signature Signature that failed
|
|
275
|
+
# @param [Hash] opts A hash containing contextual information on the error:
|
|
276
|
+
# @option opts [String] :message Error message
|
|
277
|
+
# @option opts [String] :kind One of:
|
|
278
|
+
# ['Parameter', 'Block parameter', 'Return value']
|
|
279
|
+
# @option opts [Symbol] :name Param or block param name (nil for return
|
|
280
|
+
# value)
|
|
281
|
+
# @option opts [Object] :type Expected param/return value type
|
|
282
|
+
# @option opts [Object] :value Actual param/return value
|
|
283
|
+
# @option opts [Thread::Backtrace::Location] :location Location of the
|
|
284
|
+
# caller
|
|
270
285
|
#
|
|
271
286
|
# @example
|
|
272
287
|
# T::Configuration.call_validation_error_handler = lambda do |signature, opts|
|
|
@@ -290,6 +305,7 @@ module T::Configuration
|
|
|
290
305
|
nil
|
|
291
306
|
end
|
|
292
307
|
|
|
308
|
+
@log_info_handler = nil
|
|
293
309
|
# Set a handler for logging
|
|
294
310
|
#
|
|
295
311
|
# @param [Lambda, Proc, Object, nil] value Proc that handles the error
|
|
@@ -297,8 +313,8 @@ module T::Configuration
|
|
|
297
313
|
#
|
|
298
314
|
# Parameters passed to value.call:
|
|
299
315
|
#
|
|
300
|
-
#
|
|
301
|
-
#
|
|
316
|
+
# @param [String] str Message to be logged
|
|
317
|
+
# @param [Hash] extra A hash containing additional parameters to be passed along to the logger.
|
|
302
318
|
#
|
|
303
319
|
# @example
|
|
304
320
|
# T::Configuration.log_info_handler = lambda do |str, extra|
|
|
@@ -321,6 +337,7 @@ module T::Configuration
|
|
|
321
337
|
end
|
|
322
338
|
end
|
|
323
339
|
|
|
340
|
+
@soft_assert_handler = nil
|
|
324
341
|
# Set a handler for soft assertions
|
|
325
342
|
#
|
|
326
343
|
# These generally shouldn't stop execution of the program, but rather inform
|
|
@@ -331,8 +348,8 @@ module T::Configuration
|
|
|
331
348
|
#
|
|
332
349
|
# Parameters passed to value.call:
|
|
333
350
|
#
|
|
334
|
-
#
|
|
335
|
-
#
|
|
351
|
+
# @param [String] str Assertion message
|
|
352
|
+
# @param [Hash] extra A hash containing additional parameters to be passed along to the handler.
|
|
336
353
|
#
|
|
337
354
|
# @example
|
|
338
355
|
# T::Configuration.soft_assert_handler = lambda do |str, extra|
|
|
@@ -355,6 +372,7 @@ module T::Configuration
|
|
|
355
372
|
end
|
|
356
373
|
end
|
|
357
374
|
|
|
375
|
+
@hard_assert_handler = nil
|
|
358
376
|
# Set a handler for hard assertions
|
|
359
377
|
#
|
|
360
378
|
# These generally should stop execution of the program, and optionally inform
|
|
@@ -365,8 +383,8 @@ module T::Configuration
|
|
|
365
383
|
#
|
|
366
384
|
# Parameters passed to value.call:
|
|
367
385
|
#
|
|
368
|
-
#
|
|
369
|
-
#
|
|
386
|
+
# @param [String] str Assertion message
|
|
387
|
+
# @param [Hash] extra A hash containing additional parameters to be passed along to the handler.
|
|
370
388
|
#
|
|
371
389
|
# @example
|
|
372
390
|
# T::Configuration.hard_assert_handler = lambda do |str, extra|
|
|
@@ -389,10 +407,11 @@ module T::Configuration
|
|
|
389
407
|
end
|
|
390
408
|
end
|
|
391
409
|
|
|
410
|
+
@scalar_types = nil
|
|
392
411
|
# Set a list of class strings that are to be considered scalar.
|
|
393
412
|
# (pass nil to reset to default behavior)
|
|
394
413
|
#
|
|
395
|
-
# @param [String]
|
|
414
|
+
# @param [String] values Class name.
|
|
396
415
|
#
|
|
397
416
|
# @example
|
|
398
417
|
# T::Configuration.scalar_types = ["NilClass", "TrueClass", "FalseClass", ...]
|
|
@@ -405,21 +424,21 @@ module T::Configuration
|
|
|
405
424
|
raise ArgumentError.new("Provided values must all be class name strings.")
|
|
406
425
|
end
|
|
407
426
|
|
|
408
|
-
@scalar_types =
|
|
427
|
+
@scalar_types = values.each_with_object({}) {|x, acc| acc[x] = true}.freeze
|
|
409
428
|
end
|
|
410
429
|
end
|
|
411
430
|
|
|
412
|
-
@default_scalar_types =
|
|
413
|
-
NilClass
|
|
414
|
-
TrueClass
|
|
415
|
-
FalseClass
|
|
416
|
-
Integer
|
|
417
|
-
Float
|
|
418
|
-
String
|
|
419
|
-
Symbol
|
|
420
|
-
Time
|
|
421
|
-
T::Enum
|
|
422
|
-
|
|
431
|
+
@default_scalar_types = {
|
|
432
|
+
"NilClass" => true,
|
|
433
|
+
"TrueClass" => true,
|
|
434
|
+
"FalseClass" => true,
|
|
435
|
+
"Integer" => true,
|
|
436
|
+
"Float" => true,
|
|
437
|
+
"String" => true,
|
|
438
|
+
"Symbol" => true,
|
|
439
|
+
"Time" => true,
|
|
440
|
+
"T::Enum" => true,
|
|
441
|
+
}.freeze
|
|
423
442
|
|
|
424
443
|
def self.scalar_types
|
|
425
444
|
@scalar_types || @default_scalar_types
|
|
@@ -429,10 +448,10 @@ module T::Configuration
|
|
|
429
448
|
MODULE_NAME = Module.instance_method(:name)
|
|
430
449
|
private_constant :MODULE_NAME
|
|
431
450
|
|
|
432
|
-
if T::Configuration::AT_LEAST_RUBY_2_7
|
|
433
|
-
|
|
451
|
+
@default_module_name_mangler = if T::Configuration::AT_LEAST_RUBY_2_7
|
|
452
|
+
->(type) {MODULE_NAME.bind_call(type)}
|
|
434
453
|
else
|
|
435
|
-
|
|
454
|
+
->(type) {MODULE_NAME.bind(type).call}
|
|
436
455
|
end
|
|
437
456
|
|
|
438
457
|
@module_name_mangler = nil
|
|
@@ -445,16 +464,17 @@ module T::Configuration
|
|
|
445
464
|
# to names in generated code. Used by the runtime implementation
|
|
446
465
|
# associated with `--stripe-packages` mode.
|
|
447
466
|
#
|
|
448
|
-
# @param [Lambda, Proc, nil]
|
|
467
|
+
# @param [Lambda, Proc, nil] handler Proc that converts a type (Class/Module)
|
|
449
468
|
# to a String (pass nil to reset to default behavior)
|
|
450
469
|
def self.module_name_mangler=(handler)
|
|
451
470
|
@module_name_mangler = handler
|
|
452
471
|
end
|
|
453
472
|
|
|
473
|
+
@sensitivity_and_pii_handler = nil
|
|
454
474
|
# Set to a PII handler function. This will be called with the `sensitivity:`
|
|
455
475
|
# annotations on things that use `T::Props` and can modify them ahead-of-time.
|
|
456
476
|
#
|
|
457
|
-
# @param [Lambda, Proc, nil]
|
|
477
|
+
# @param [Lambda, Proc, nil] handler Proc that takes a hash mapping symbols to the
|
|
458
478
|
# prop values. Pass nil to avoid changing `sensitivity:` annotations.
|
|
459
479
|
def self.normalize_sensitivity_and_pii_handler=(handler)
|
|
460
480
|
@sensitivity_and_pii_handler = handler
|
|
@@ -470,7 +490,7 @@ module T::Configuration
|
|
|
470
490
|
# `nil` and will raise an exception when the redacted version of a prop is
|
|
471
491
|
# accessed.
|
|
472
492
|
#
|
|
473
|
-
# @param [Lambda, Proc, nil]
|
|
493
|
+
# @param [Lambda, Proc, nil] handler Proc that converts a value into its
|
|
474
494
|
# redacted version according to the spec passed as the second argument.
|
|
475
495
|
def self.redaction_handler=(handler)
|
|
476
496
|
@redaction_handler = handler
|
|
@@ -480,10 +500,11 @@ module T::Configuration
|
|
|
480
500
|
@redaction_handler
|
|
481
501
|
end
|
|
482
502
|
|
|
503
|
+
@class_owner_finder = nil
|
|
483
504
|
# Set to a function which can get the 'owner' of a class. This is
|
|
484
505
|
# used in reporting deserialization errors
|
|
485
506
|
#
|
|
486
|
-
# @param [Lambda, Proc, nil]
|
|
507
|
+
# @param [Lambda, Proc, nil] handler Proc that takes a class and
|
|
487
508
|
# produces its owner, or `nil` if it does not have one.
|
|
488
509
|
def self.class_owner_finder=(handler)
|
|
489
510
|
@class_owner_finder = handler
|
|
@@ -513,6 +534,7 @@ module T::Configuration
|
|
|
513
534
|
end
|
|
514
535
|
end
|
|
515
536
|
|
|
537
|
+
@legacy_t_enum_migration_mode = false
|
|
516
538
|
def self.enable_legacy_t_enum_migration_mode
|
|
517
539
|
@legacy_t_enum_migration_mode = true
|
|
518
540
|
end
|
|
@@ -523,6 +545,17 @@ module T::Configuration
|
|
|
523
545
|
@legacy_t_enum_migration_mode || false
|
|
524
546
|
end
|
|
525
547
|
|
|
548
|
+
@prop_freeze_handler = ->(instance, prop_name) {}
|
|
549
|
+
|
|
550
|
+
def self.prop_freeze_handler=(handler)
|
|
551
|
+
@prop_freeze_handler = handler
|
|
552
|
+
end
|
|
553
|
+
|
|
554
|
+
def self.prop_freeze_handler
|
|
555
|
+
@prop_freeze_handler
|
|
556
|
+
end
|
|
557
|
+
|
|
558
|
+
@sealed_violation_whitelist = nil
|
|
526
559
|
# @param [Array] sealed_violation_whitelist An array of Regexp to validate
|
|
527
560
|
# whether inheriting /including a sealed module outside the defining module
|
|
528
561
|
# should be allowed. Useful to whitelist benign violations, like shim files
|
data/lib/types/enum.rb
CHANGED
|
@@ -47,7 +47,7 @@ class T::Enum
|
|
|
47
47
|
SerializedVal = T.type_alias {T.untyped}
|
|
48
48
|
private_constant :SerializedVal
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
### Enum class methods ###
|
|
51
51
|
sig {returns(T::Array[T.attached_class])}
|
|
52
52
|
def self.values
|
|
53
53
|
if @values.nil?
|
|
@@ -134,9 +134,7 @@ class T::Enum
|
|
|
134
134
|
self.from_serialized(mongo_value)
|
|
135
135
|
end
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
## Enum instance methods ##
|
|
139
|
-
|
|
137
|
+
### Enum instance methods ###
|
|
140
138
|
|
|
141
139
|
sig {returns(T.self_type)}
|
|
142
140
|
def dup
|
|
@@ -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,9 +243,7 @@ class T::Enum
|
|
|
246
243
|
)
|
|
247
244
|
end
|
|
248
245
|
|
|
249
|
-
|
|
250
|
-
## Private implementation ##
|
|
251
|
-
|
|
246
|
+
### Private implementation ###
|
|
252
247
|
|
|
253
248
|
sig {params(serialized_val: SerializedVal).void}
|
|
254
249
|
def initialize(serialized_val=nil)
|
|
@@ -291,14 +286,18 @@ class T::Enum
|
|
|
291
286
|
|
|
292
287
|
sig {returns(T::Boolean)}
|
|
293
288
|
def self.started_initializing?
|
|
294
|
-
|
|
295
|
-
|
|
289
|
+
unless defined?(@started_initializing)
|
|
290
|
+
@started_initializing = T.let(false, T.nilable(T::Boolean))
|
|
291
|
+
end
|
|
292
|
+
T.must(@started_initializing)
|
|
296
293
|
end
|
|
297
294
|
|
|
298
295
|
sig {returns(T::Boolean)}
|
|
299
296
|
def self.fully_initialized?
|
|
300
|
-
|
|
301
|
-
|
|
297
|
+
unless defined?(@fully_initialized)
|
|
298
|
+
@fully_initialized = T.let(false, T.nilable(T::Boolean))
|
|
299
|
+
end
|
|
300
|
+
T.must(@fully_initialized)
|
|
302
301
|
end
|
|
303
302
|
|
|
304
303
|
# Maintains the order in which values are defined
|
|
@@ -313,8 +312,8 @@ class T::Enum
|
|
|
313
312
|
sig {params(blk: T.proc.void).void}
|
|
314
313
|
def self.enums(&blk)
|
|
315
314
|
raise "enums cannot be defined for T::Enum" if self == T::Enum
|
|
316
|
-
raise "Enum #{self} was already initialized" if
|
|
317
|
-
raise "Enum #{self} is still initializing" if
|
|
315
|
+
raise "Enum #{self} was already initialized" if fully_initialized?
|
|
316
|
+
raise "Enum #{self} is still initializing" if started_initializing?
|
|
318
317
|
|
|
319
318
|
@started_initializing = true
|
|
320
319
|
|
|
@@ -366,6 +365,6 @@ class T::Enum
|
|
|
366
365
|
|
|
367
366
|
sig {params(args: String).returns(T.attached_class)}
|
|
368
367
|
def self._load(args)
|
|
369
|
-
deserialize(Marshal.load(args))
|
|
368
|
+
deserialize(Marshal.load(args)) # rubocop:disable Security/MarshalLoad
|
|
370
369
|
end
|
|
371
370
|
end
|
data/lib/types/generic.rb
CHANGED
|
@@ -12,11 +12,13 @@ module T::Generic
|
|
|
12
12
|
self
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
# TODO(jez) Remove these keyword arguments once it's a static error
|
|
16
|
+
def type_member(variance=:invariant, fixed: nil, lower: T.untyped, upper: BasicObject, &blk)
|
|
16
17
|
T::Types::TypeMember.new(variance)
|
|
17
18
|
end
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
# TODO(jez) Remove these keyword arguments once it's a static error
|
|
21
|
+
def type_template(variance=:invariant, fixed: nil, lower: T.untyped, upper: BasicObject, &blk)
|
|
20
22
|
T::Types::TypeTemplate.new(variance)
|
|
21
23
|
end
|
|
22
24
|
end
|
data/lib/types/helpers.rb
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
# Use as a mixin with extend (`extend T::Helpers`).
|
|
5
5
|
# Docs at https://confluence.corp.stripe.com/display/PRODINFRA/Ruby+Types
|
|
6
6
|
module T::Helpers
|
|
7
|
+
extend T::Sig
|
|
8
|
+
|
|
7
9
|
Private = T::Private
|
|
8
10
|
|
|
9
11
|
### Class/Module Helpers ###
|
|
@@ -44,7 +46,7 @@ module T::Helpers
|
|
|
44
46
|
# module MyHelper
|
|
45
47
|
# extend T::Helpers
|
|
46
48
|
#
|
|
47
|
-
# requires_ancestor Kernel
|
|
49
|
+
# requires_ancestor { Kernel }
|
|
48
50
|
# end
|
|
49
51
|
#
|
|
50
52
|
# class MyClass < BasicObject # error: `MyClass` must include `Kernel` (required by `MyHelper`)
|
|
@@ -52,5 +54,5 @@ module T::Helpers
|
|
|
52
54
|
# end
|
|
53
55
|
#
|
|
54
56
|
# TODO: implement the checks in sorbet-runtime.
|
|
55
|
-
def requires_ancestor(
|
|
57
|
+
def requires_ancestor(&block); end
|
|
56
58
|
end
|
|
@@ -43,17 +43,17 @@ class T::InterfaceWrapper
|
|
|
43
43
|
def initialize(target_obj, interface_mod)
|
|
44
44
|
if target_obj.is_a?(T::InterfaceWrapper)
|
|
45
45
|
# wrapped_dynamic_cast should guarantee this never happens.
|
|
46
|
-
raise "Unexpected: wrapping a wrapper. Please report
|
|
46
|
+
raise "Unexpected: wrapping a wrapper. Please report this bug at https://github.com/sorbet/sorbet/issues"
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
if !target_obj.is_a?(interface_mod)
|
|
50
50
|
# wrapped_dynamic_cast should guarantee this never happens.
|
|
51
|
-
raise "Unexpected: `is_a?` failed. Please report
|
|
51
|
+
raise "Unexpected: `is_a?` failed. Please report this bug at https://github.com/sorbet/sorbet/issues"
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
if target_obj.class == interface_mod
|
|
55
55
|
# wrapped_dynamic_cast should guarantee this never happens.
|
|
56
|
-
raise "Unexpected: exact class match. Please report
|
|
56
|
+
raise "Unexpected: exact class match. Please report this bug at https://github.com/sorbet/sorbet/issues"
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
@target_obj = target_obj
|
|
@@ -78,7 +78,7 @@ class T::InterfaceWrapper
|
|
|
78
78
|
elsif target_obj.singleton_class.private_method_defined?(method_name)
|
|
79
79
|
singleton_class.send(:private, method_name)
|
|
80
80
|
else
|
|
81
|
-
raise "This should never happen. Report
|
|
81
|
+
raise "This should never happen. Report this bug at https://github.com/sorbet/sorbet/issues"
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
84
|
end
|
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
# typed: strict
|
|
3
3
|
|
|
4
4
|
module T::NonForcingConstants
|
|
5
|
-
T::Sig::WithoutRuntime.sig {returns(T::Boolean)}
|
|
6
|
-
private_class_method def self.stripe_packages_enabled?
|
|
7
|
-
const_defined?('StripePackages') && const_get('StripePackages').enabled?
|
|
8
|
-
end
|
|
9
|
-
|
|
10
5
|
# NOTE: This method is documented on the RBI in Sorbet's payload, so that it
|
|
11
6
|
# shows up in the hover/completion documentation via LSP.
|
|
12
7
|
T::Sig::WithoutRuntime.sig {params(val: BasicObject, klass: String, package: T.nilable(String)).returns(T::Boolean)}
|
|
@@ -16,10 +11,11 @@ module T::NonForcingConstants
|
|
|
16
11
|
raise ArgumentError.new("The string given to `#{method_name}` must not be empty")
|
|
17
12
|
end
|
|
18
13
|
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
# We don't treat packages differently at runtime, but the static
|
|
15
|
+
# type-checker still needs to have the package and constant
|
|
16
|
+
# separated out. This just re-assembles the string as needed
|
|
17
|
+
if !package.nil?
|
|
18
|
+
klass = "::#{package}::#{klass}"
|
|
23
19
|
end
|
|
24
20
|
|
|
25
21
|
current_klass = T.let(nil, T.nilable(Module))
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
# modules that override the `hash` method with something completely broken.
|
|
13
13
|
module T::Private::Abstract::Data
|
|
14
14
|
def self.get(mod, key)
|
|
15
|
-
mod.instance_variable_get("@opus_abstract__#{key}")
|
|
15
|
+
mod.instance_variable_get("@opus_abstract__#{key}") if key?(mod, key)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def self.set(mod, key, value)
|
|
@@ -40,6 +40,11 @@ module T::Private::Abstract::Declare
|
|
|
40
40
|
end
|
|
41
41
|
super(*args, &blk)
|
|
42
42
|
end
|
|
43
|
+
|
|
44
|
+
# Ruby doesn not emit "method redefined" warnings for aliased methods
|
|
45
|
+
# (more robust than undef_method that would create a small window in which the method doesn't exist)
|
|
46
|
+
mod.send(:alias_method, :initialize, :initialize)
|
|
47
|
+
|
|
43
48
|
if mod.respond_to?(:ruby2_keywords, true)
|
|
44
49
|
mod.send(:ruby2_keywords, :initialize)
|
|
45
50
|
end
|
|
@@ -37,7 +37,6 @@ module T::Private::Abstract::Hooks
|
|
|
37
37
|
private def prepended(other)
|
|
38
38
|
# Prepending abstract methods is weird. You'd only be able to override them via other prepended
|
|
39
39
|
# modules, or in subclasses. Punt until we have a use case.
|
|
40
|
-
Kernel.raise "Prepending abstract mixins is not currently supported.
|
|
41
|
-
"to #dev-productivity."
|
|
40
|
+
Kernel.raise "Prepending abstract mixins is not currently supported."
|
|
42
41
|
end
|
|
43
42
|
end
|