sorbet-runtime 0.6.13455 → 0.6.13558
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 +0 -32
- data/lib/types/private/methods/call_validation.rb +22 -7
- data/lib/types/private/types/not_typed.rb +5 -0
- data/lib/types/private/types/string_holder.rb +5 -0
- data/lib/types/private/types/type_alias.rb +7 -0
- data/lib/types/private/types/void.rb +5 -0
- data/lib/types/props/serializable.rb +13 -4
- data/lib/types/types/anything.rb +5 -0
- data/lib/types/types/attached_class.rb +5 -0
- data/lib/types/types/base.rb +11 -0
- data/lib/types/types/class_of.rb +5 -0
- data/lib/types/types/enum.rb +6 -0
- data/lib/types/types/fixed_array.rb +6 -0
- data/lib/types/types/fixed_hash.rb +6 -0
- data/lib/types/types/intersection.rb +6 -0
- data/lib/types/types/noreturn.rb +5 -0
- data/lib/types/types/proc.rb +7 -0
- data/lib/types/types/self_type.rb +5 -0
- data/lib/types/types/simple.rb +8 -0
- data/lib/types/types/t_enum.rb +5 -0
- data/lib/types/types/type_parameter.rb +5 -0
- data/lib/types/types/type_variable.rb +5 -0
- data/lib/types/types/typed_class.rb +6 -0
- data/lib/types/types/typed_enumerable.rb +6 -0
- data/lib/types/types/typed_module.rb +6 -0
- data/lib/types/types/union.rb +6 -0
- data/lib/types/types/untyped.rb +5 -0
- data/lib/types/utils.rb +13 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 28fdc76a685d7fe5085b89732a4aec05fa803bd38313c1ad26359dfaf93deb09
|
|
4
|
+
data.tar.gz: 5df93e5b8be311fb7cfd52d7587439d6d52ee00704b5819d566e93af88385396
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 47b078b793fd134133fffe4765c7623d02a1fa2f312f59fd75b795c791922a75fbba3df1ac4a5bdec9873cf3067b8c904d77ec0113c1d12e926cecbf019893af
|
|
7
|
+
data.tar.gz: 97079b47fdc95608f7f81edc16bf090513b1da88503ab1663074303b2c8bbe050241bbad9a04412e90472e72fcdebc820be4e5ed825105b1baa18beb924fa8dd
|
data/lib/types/configuration.rb
CHANGED
|
@@ -270,38 +270,6 @@ module T::Configuration
|
|
|
270
270
|
nil
|
|
271
271
|
end
|
|
272
272
|
|
|
273
|
-
@log_info_handler = nil
|
|
274
|
-
# Set a handler for logging
|
|
275
|
-
#
|
|
276
|
-
# @param [Lambda, Proc, Object, nil] value Proc that handles the error
|
|
277
|
-
# report (pass nil to reset to default behavior)
|
|
278
|
-
#
|
|
279
|
-
# Parameters passed to value.call:
|
|
280
|
-
#
|
|
281
|
-
# @param [String] str Message to be logged
|
|
282
|
-
# @param [Hash] extra A hash containing additional parameters to be passed along to the logger.
|
|
283
|
-
#
|
|
284
|
-
# @example
|
|
285
|
-
# T::Configuration.log_info_handler = lambda do |str, extra|
|
|
286
|
-
# puts "#{str}, context: #{extra}"
|
|
287
|
-
# end
|
|
288
|
-
def self.log_info_handler=(value)
|
|
289
|
-
validate_lambda_given!(value)
|
|
290
|
-
@log_info_handler = value
|
|
291
|
-
end
|
|
292
|
-
|
|
293
|
-
private_class_method def self.log_info_handler_default(str, extra)
|
|
294
|
-
puts "#{str}, extra: #{extra}"
|
|
295
|
-
end
|
|
296
|
-
|
|
297
|
-
def self.log_info_handler(str, extra)
|
|
298
|
-
if @log_info_handler
|
|
299
|
-
@log_info_handler.call(str, extra)
|
|
300
|
-
else
|
|
301
|
-
log_info_handler_default(str, extra)
|
|
302
|
-
end
|
|
303
|
-
end
|
|
304
|
-
|
|
305
273
|
@soft_assert_handler = nil
|
|
306
274
|
# Set a handler for soft assertions
|
|
307
275
|
#
|
|
@@ -7,7 +7,8 @@ module T::Private::Methods::CallValidation
|
|
|
7
7
|
|
|
8
8
|
KERNEL_TO_S = Kernel.instance_method(:to_s)
|
|
9
9
|
MODULE_TO_S = Module.instance_method(:to_s)
|
|
10
|
-
|
|
10
|
+
METHOD_NAME_FOR_EVAL = /\A[A-Za-z_][A-Za-z0-9_]*[!?]?\z/
|
|
11
|
+
private_constant(:KERNEL_TO_S, :MODULE_TO_S, :METHOD_NAME_FOR_EVAL)
|
|
11
12
|
|
|
12
13
|
# Wraps a method with a layer of validation for the given type signature.
|
|
13
14
|
# This wrapper is meant to be fast, and is applied by a previous wrapper,
|
|
@@ -52,21 +53,35 @@ module T::Private::Methods::CallValidation
|
|
|
52
53
|
def self.create_abstract_wrapper(mod, method_name, original_visibility)
|
|
53
54
|
T::Configuration.without_ruby_warnings do
|
|
54
55
|
T::Private::DeclState.current.without_on_method_added do
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
if METHOD_NAME_FOR_EVAL.match?(method_name)
|
|
57
|
+
mod.module_eval(<<~METHOD, __FILE__, __LINE__ + 1)
|
|
58
|
+
#{original_visibility}
|
|
59
|
+
|
|
60
|
+
def #{method_name}(...)
|
|
61
|
+
# We allow abstract methods to be implemented by things further down the ancestor chain.
|
|
62
|
+
# So, if a super method exists, call it.
|
|
63
|
+
if defined?(super)
|
|
64
|
+
super
|
|
65
|
+
else
|
|
66
|
+
raise NotImplementedError.new(
|
|
67
|
+
"The method `#{method_name}` on #{mod} is declared as `abstract`. It does not have an implementation."
|
|
68
|
+
)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
METHOD
|
|
72
|
+
else
|
|
73
|
+
T::Private::ClassUtils.def_with_visibility(mod, method_name, original_visibility) do |*args, &blk|
|
|
59
74
|
# We allow abstract methods to be implemented by things further down the ancestor chain.
|
|
60
75
|
# So, if a super method exists, call it.
|
|
61
76
|
if defined?(super)
|
|
62
|
-
super
|
|
77
|
+
super(*args, &blk)
|
|
63
78
|
else
|
|
64
79
|
raise NotImplementedError.new(
|
|
65
80
|
"The method `#{method_name}` on #{mod} is declared as `abstract`. It does not have an implementation."
|
|
66
81
|
)
|
|
67
82
|
end
|
|
68
83
|
end
|
|
69
|
-
|
|
84
|
+
end
|
|
70
85
|
end
|
|
71
86
|
end
|
|
72
87
|
end
|
|
@@ -25,6 +25,13 @@ module T::Private::Types
|
|
|
25
25
|
nil
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
# overrides Base
|
|
29
|
+
def build_lazy_fields
|
|
30
|
+
# Not the aliased type too: an alias can refer to itself.
|
|
31
|
+
effective_aliased_type
|
|
32
|
+
nil
|
|
33
|
+
end
|
|
34
|
+
|
|
28
35
|
def aliased_type
|
|
29
36
|
@aliased_type ||= T::Utils.coerce(@callable.call)
|
|
30
37
|
end
|
|
@@ -141,10 +141,7 @@ module T::Props::Serializable
|
|
|
141
141
|
# If the prop was already missing during deserialization, that means the application
|
|
142
142
|
# code already had to deal with a nil value, which means we wouldn't be accomplishing
|
|
143
143
|
# much by raising here (other than causing an unnecessary breakage).
|
|
144
|
-
|
|
145
|
-
"chalk-odm: missing required property in serialize",
|
|
146
|
-
prop: prop, class: self.class.name, id: self.class.decorator.get_id(self)
|
|
147
|
-
)
|
|
144
|
+
Kernel.warn("chalk-odm: missing required property in serialize prop=#{prop.inspect} class=#{self.class.name} id=#{self.class.decorator.get_id(self).inspect}")
|
|
148
145
|
else
|
|
149
146
|
raise TypeError.new("#{self.class.name}.#{prop} not set for non-optional prop")
|
|
150
147
|
end
|
|
@@ -289,6 +286,18 @@ module T::Props::Serializable::DecoratorMethods
|
|
|
289
286
|
raise ArgumentError.new("The value of `raise_on_nil_write` if specified must be `true` (given: #{rules[:raise_on_nil_write]}).")
|
|
290
287
|
end
|
|
291
288
|
|
|
289
|
+
if rules[:raise_on_nil_write] && !rules[:_tnilable]
|
|
290
|
+
is_nilclass_parent = type.is_a?(T::Types::Simple) &&
|
|
291
|
+
(type.raw_type.equal?(Object) || type.raw_type.equal?(BasicObject))
|
|
292
|
+
# Use `instance_of?` because modules can be mixed into NilClass, but classes cannot.
|
|
293
|
+
is_module = type.is_a?(T::Types::Simple) && type.raw_type.instance_of?(Module)
|
|
294
|
+
underspecified_type = type.equal?(T.untyped) || is_nilclass_parent || is_module
|
|
295
|
+
|
|
296
|
+
unless underspecified_type
|
|
297
|
+
raise ArgumentError.new("`raise_on_nil_write` requires that the type of `#{name}` be `T.nilable(...)` (given: #{type})")
|
|
298
|
+
end
|
|
299
|
+
end
|
|
300
|
+
|
|
292
301
|
result
|
|
293
302
|
end
|
|
294
303
|
|
data/lib/types/types/anything.rb
CHANGED
data/lib/types/types/base.rb
CHANGED
|
@@ -39,6 +39,17 @@ module T::Types
|
|
|
39
39
|
raise NotImplementedError
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
# Force every lazily-initialized field of this type and its inner types to be built.
|
|
43
|
+
# It's unusual to call this directly; you probably want to call it indirectly via `T::Utils.build_all_types`.
|
|
44
|
+
define_method(:build_lazy_fields) do
|
|
45
|
+
raise NotImplementedError
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# A frozen type can't take the write, so skip it.
|
|
49
|
+
private def build_inner_lazy_fields(inner)
|
|
50
|
+
inner.build_lazy_fields unless inner.frozen?
|
|
51
|
+
end
|
|
52
|
+
|
|
42
53
|
# Equality is based on name, so be sure the name reflects all relevant state when implementing.
|
|
43
54
|
define_method(:name) do
|
|
44
55
|
raise NotImplementedError
|
data/lib/types/types/class_of.rb
CHANGED
data/lib/types/types/enum.rb
CHANGED
data/lib/types/types/noreturn.rb
CHANGED
data/lib/types/types/proc.rb
CHANGED
data/lib/types/types/simple.rb
CHANGED
|
@@ -17,6 +17,14 @@ module T::Types
|
|
|
17
17
|
nil
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
+
# overrides Base
|
|
21
|
+
def build_lazy_fields
|
|
22
|
+
name
|
|
23
|
+
# NilClass can't be paired with itself in a SimplePairUnion.
|
|
24
|
+
to_nilable.types unless @raw_type.equal?(NilClass)
|
|
25
|
+
nil
|
|
26
|
+
end
|
|
27
|
+
|
|
20
28
|
# overrides Base
|
|
21
29
|
def name
|
|
22
30
|
# Memoize to mitigate pathological performance with anonymous modules (https://bugs.ruby-lang.org/issues/11119)
|
data/lib/types/types/t_enum.rb
CHANGED
data/lib/types/types/union.rb
CHANGED
|
@@ -42,6 +42,12 @@ module T::Types
|
|
|
42
42
|
nil
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
+
# overrides Base
|
|
46
|
+
def build_lazy_fields
|
|
47
|
+
types.each { |type| build_inner_lazy_fields(type) }
|
|
48
|
+
nil
|
|
49
|
+
end
|
|
50
|
+
|
|
45
51
|
# overrides Base
|
|
46
52
|
def name
|
|
47
53
|
# Use the attr_reader here so we can override it in SimplePairUnion
|
data/lib/types/types/untyped.rb
CHANGED
data/lib/types/utils.rb
CHANGED
|
@@ -178,6 +178,19 @@ module T::Utils
|
|
|
178
178
|
nil
|
|
179
179
|
end
|
|
180
180
|
|
|
181
|
+
# Force every type object in the process to build its lazily-initialized
|
|
182
|
+
# fields (see `T::Types::Base#build_lazy_fields`).
|
|
183
|
+
#
|
|
184
|
+
# Call this before forking workers so that first use of a type in a worker
|
|
185
|
+
# doesn't write onto a type object shared with the parent via copy-on-write.
|
|
186
|
+
def self.build_all_types
|
|
187
|
+
require 'objspace'
|
|
188
|
+
ObjectSpace.each_object(T::Types::Base) do |type|
|
|
189
|
+
type.build_lazy_fields unless type.frozen?
|
|
190
|
+
end
|
|
191
|
+
nil
|
|
192
|
+
end
|
|
193
|
+
|
|
181
194
|
def self.lift_enum(enum)
|
|
182
195
|
unless enum.is_a?(T::Types::Enum)
|
|
183
196
|
raise ArgumentError.new("#{enum.inspect} is not a T.deprecated_enum")
|