sorbet-runtime 0.4.4432 → 0.4.4433
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/configuration.rb +20 -0
- data/lib/types/private/abstract/declare.rb +3 -0
- data/lib/types/private/class_utils.rb +7 -3
- data/lib/types/private/methods/call_validation.rb +13 -9
- data/lib/types/props/decorator.rb +12 -10
- data/lib/types/sig.rb +5 -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: 806ef6364f091901907ddc865da6bd63decebb6f
|
4
|
+
data.tar.gz: e0d3d1f61afacc778ad00ee195b5c46375690f62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8329ace77948ad758ce392d51b9d0103039d4a2a5d73b302e904542410e27f796c6cf16f596e1373d8c6c1048a44333a13a5157fe36d59f4a763b06460db7f6a
|
7
|
+
data.tar.gz: 2cc760a30cdd7b2218c2ce61f6e8a6e174ea60274881e1e22db16329c2a6537a8cfb41ca469283c0a3a6fffcd3c2082252e068bbe7d24cc664ea606d3171f972
|
data/lib/types/configuration.rb
CHANGED
@@ -333,6 +333,26 @@ module T::Configuration
|
|
333
333
|
@scalar_types || @default_scalar_types
|
334
334
|
end
|
335
335
|
|
336
|
+
# Temporarily disable ruby warnings while executing the given block. This is
|
337
|
+
# useful when doing something that would normally cause a warning to be
|
338
|
+
# emitted in Ruby verbose mode ($VERBOSE = true).
|
339
|
+
#
|
340
|
+
# @yield
|
341
|
+
#
|
342
|
+
def self.without_ruby_warnings
|
343
|
+
if $VERBOSE
|
344
|
+
begin
|
345
|
+
original_verbose = $VERBOSE
|
346
|
+
$VERBOSE = false
|
347
|
+
yield
|
348
|
+
ensure
|
349
|
+
$VERBOSE = original_verbose
|
350
|
+
end
|
351
|
+
else
|
352
|
+
yield
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
336
356
|
|
337
357
|
private_class_method def self.validate_lambda_given!(value)
|
338
358
|
if !value.nil? && !value.respond_to?(:call)
|
@@ -28,6 +28,9 @@ module T::Private::Abstract::Declare
|
|
28
28
|
raise "You must call `abstract!` *before* defining an initialize method"
|
29
29
|
end
|
30
30
|
|
31
|
+
# Don't need to silence warnings via without_ruby_warnings when calling
|
32
|
+
# define_method because of the guard above
|
33
|
+
|
31
34
|
mod.send(:define_method, :initialize) do |*args, &blk|
|
32
35
|
if self.class == mod
|
33
36
|
raise "#{mod} is declared as abstract; it cannot be instantiated"
|
@@ -32,7 +32,9 @@ module T::Private::ClassUtils
|
|
32
32
|
|
33
33
|
if @overwritten
|
34
34
|
# The original method was overwritten. Overwrite again to restore it.
|
35
|
-
|
35
|
+
T::Configuration.without_ruby_warnings do
|
36
|
+
@mod.send(:define_method, @old_method.name, @old_method) # rubocop:disable PrisonGuard/UsePublicSend
|
37
|
+
end
|
36
38
|
else
|
37
39
|
# The original method was in an ancestor. Restore it by removing the overriding method.
|
38
40
|
@mod.send(:remove_method, @old_method.name) # rubocop:disable PrisonGuard/UsePublicSend
|
@@ -93,8 +95,10 @@ module T::Private::ClassUtils
|
|
93
95
|
end
|
94
96
|
|
95
97
|
overwritten = original_owner == mod
|
96
|
-
|
97
|
-
|
98
|
+
T::Configuration.without_ruby_warnings do
|
99
|
+
mod.send(:define_method, name, &blk) # rubocop:disable PrisonGuard/UsePublicSend
|
100
|
+
mod.send(original_visibility, name) # rubocop:disable PrisonGuard/UsePublicSend
|
101
|
+
end
|
98
102
|
new_method = mod.instance_method(name)
|
99
103
|
|
100
104
|
ReplacedMethod.new(mod, original_method, new_method, overwritten, original_visibility)
|
@@ -35,9 +35,11 @@ module T::Private::Methods::CallValidation
|
|
35
35
|
elsif method_sig.check_level == :always || (method_sig.check_level == :tests && T::Private::RuntimeLevels.check_tests?)
|
36
36
|
create_validator_method(mod, original_method, method_sig, original_visibility)
|
37
37
|
else
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
T::Configuration.without_ruby_warnings do
|
39
|
+
# get all the shims out of the way and put back the original method
|
40
|
+
mod.send(:define_method, method_sig.method_name, original_method)
|
41
|
+
mod.send(original_visibility, method_sig.method_name)
|
42
|
+
end
|
41
43
|
end
|
42
44
|
# Return the newly created method (or the original one if we didn't replace it)
|
43
45
|
mod.instance_method(method_sig.method_name)
|
@@ -167,12 +169,14 @@ module T::Private::Methods::CallValidation
|
|
167
169
|
has_simple_method_types = all_args_are_simple && method_sig.return_type.is_a?(T::Types::Simple)
|
168
170
|
has_simple_procedure_types = all_args_are_simple && method_sig.return_type.is_a?(T::Private::Types::Void)
|
169
171
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
172
|
+
T::Configuration.without_ruby_warnings do
|
173
|
+
if has_fixed_arity && has_simple_method_types && method_sig.arg_types.length < 5 && is_allowed_to_have_fast_path
|
174
|
+
create_validator_method_fast(mod, original_method, method_sig)
|
175
|
+
elsif has_fixed_arity && has_simple_procedure_types && method_sig.arg_types.length < 5 && is_allowed_to_have_fast_path
|
176
|
+
create_validator_procedure_fast(mod, original_method, method_sig)
|
177
|
+
else
|
178
|
+
create_validator_slow(mod, original_method, method_sig)
|
179
|
+
end
|
176
180
|
end
|
177
181
|
mod.send(original_visibility, method_sig.method_name)
|
178
182
|
end
|
@@ -485,18 +485,20 @@ class T::Props::Decorator
|
|
485
485
|
|
486
486
|
sig {params(name: Symbol, rules: Rules).void}
|
487
487
|
private def define_getter_and_setter(name, rules)
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
488
|
+
T::Configuration.without_ruby_warnings do
|
489
|
+
if rules[:immutable]
|
490
|
+
@class.send(:define_method, "#{name}=") do |_x|
|
491
|
+
raise T::Props::ImmutableProp.new("#{self.class}##{name} cannot be modified after creation.")
|
492
|
+
end
|
493
|
+
else
|
494
|
+
@class.send(:define_method, "#{name}=") do |x|
|
495
|
+
self.class.decorator.prop_set(self, name, x, rules)
|
496
|
+
end
|
495
497
|
end
|
496
|
-
end
|
497
498
|
|
498
|
-
|
499
|
-
|
499
|
+
@class.send(:define_method, name) do
|
500
|
+
self.class.decorator.prop_get(self, name, rules)
|
501
|
+
end
|
500
502
|
end
|
501
503
|
end
|
502
504
|
|
data/lib/types/sig.rb
CHANGED
@@ -9,10 +9,15 @@ module T::Sig
|
|
9
9
|
# as T::Sig#sig. Only use it in cases where you can't use T::Sig#sig.
|
10
10
|
def self.sig(&blk); end # rubocop:disable PrisonGuard/BanBuiltinMethodOverride
|
11
11
|
|
12
|
+
original_verbose = $VERBOSE
|
13
|
+
$VERBOSE = false
|
14
|
+
|
12
15
|
# At runtime, does nothing, but statically it is treated exactly the same
|
13
16
|
# as T::Sig#sig. Only use it in cases where you can't use T::Sig#sig.
|
14
17
|
T::Sig::WithoutRuntime.sig {params(blk: T.proc.bind(T::Private::Methods::DeclBuilder).void).void}
|
15
18
|
def self.sig(&blk); end # rubocop:disable PrisonGuard/BanBuiltinMethodOverride, Lint/DuplicateMethods
|
19
|
+
|
20
|
+
$VERBOSE = original_verbose
|
16
21
|
end
|
17
22
|
|
18
23
|
# Declares a method with type signatures and/or
|