sorbet-runtime 0.5.9267 → 0.5.9291
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/private/sealed.rb +15 -12
- data/lib/types/props/decorator.rb +2 -44
- data/lib/types/types/base.rb +6 -2
- data/lib/types/types/simple.rb +17 -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: 96fecd9fed07a4fc62f4c1d6919ffb8309ad93dd6bc6fb1fff54a7dbc6a62c3e
|
4
|
+
data.tar.gz: 077f2995f9722bd657d44b2e8fedba0766808cbc117b12dd8294450c1acae8d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d83e6803524f46463e431e1b867b003d6e1f99a21ee4564b0157e95c8315b75900c7d89caf0f8866279234b4ee5b9cd427b4ab0b8cfdd833b7f047c1ac52836
|
7
|
+
data.tar.gz: 705e848b18ea78e783a1f8794a53f3eb676cabfa17438e48a6d671185084eb9165a2a27e4e8e1916e0757f4ca475b4b0d2dec02678519a943df965c68ea94974
|
data/lib/types/private/sealed.rb
CHANGED
@@ -3,11 +3,11 @@
|
|
3
3
|
|
4
4
|
module T::Private::Sealed
|
5
5
|
module NoInherit
|
6
|
-
def inherited(
|
6
|
+
def inherited(child)
|
7
7
|
super
|
8
8
|
this_line = Kernel.caller.find {|line| !line.match(/in `inherited'$/)}
|
9
|
-
T::Private::Sealed.validate_inheritance(this_line, self, 'inherited')
|
10
|
-
@sorbet_sealed_module_all_subclasses <<
|
9
|
+
T::Private::Sealed.validate_inheritance(this_line, self, child, 'inherited')
|
10
|
+
@sorbet_sealed_module_all_subclasses << child
|
11
11
|
end
|
12
12
|
|
13
13
|
def sealed_subclasses
|
@@ -20,18 +20,18 @@ module T::Private::Sealed
|
|
20
20
|
end
|
21
21
|
|
22
22
|
module NoIncludeExtend
|
23
|
-
def included(
|
23
|
+
def included(child)
|
24
24
|
super
|
25
25
|
this_line = Kernel.caller.find {|line| !line.match(/in `included'$/)}
|
26
|
-
T::Private::Sealed.validate_inheritance(this_line, self, 'included')
|
27
|
-
@sorbet_sealed_module_all_subclasses <<
|
26
|
+
T::Private::Sealed.validate_inheritance(this_line, self, child, 'included')
|
27
|
+
@sorbet_sealed_module_all_subclasses << child
|
28
28
|
end
|
29
29
|
|
30
|
-
def extended(
|
30
|
+
def extended(child)
|
31
31
|
super
|
32
32
|
this_line = Kernel.caller.find {|line| !line.match(/in `extended'$/)}
|
33
|
-
T::Private::Sealed.validate_inheritance(this_line, self, 'extended')
|
34
|
-
@sorbet_sealed_module_all_subclasses <<
|
33
|
+
T::Private::Sealed.validate_inheritance(this_line, self, child, 'extended')
|
34
|
+
@sorbet_sealed_module_all_subclasses << child
|
35
35
|
end
|
36
36
|
|
37
37
|
def sealed_subclasses
|
@@ -68,12 +68,15 @@ module T::Private::Sealed
|
|
68
68
|
mod.instance_variable_defined?(:@sorbet_sealed_module_decl_file)
|
69
69
|
end
|
70
70
|
|
71
|
-
def self.validate_inheritance(this_line, parent, verb)
|
71
|
+
def self.validate_inheritance(this_line, parent, child, verb)
|
72
72
|
this_file = this_line&.split(':')&.first
|
73
73
|
decl_file = parent.instance_variable_get(:@sorbet_sealed_module_decl_file)
|
74
74
|
|
75
|
-
if !this_file
|
76
|
-
raise "
|
75
|
+
if !this_file
|
76
|
+
raise "Could not use backtrace to determine file for #{verb} child #{child}"
|
77
|
+
end
|
78
|
+
if !decl_file
|
79
|
+
raise "#{parent} does not seem to be a sealed module (#{verb} by #{child})"
|
77
80
|
end
|
78
81
|
|
79
82
|
if !this_file.start_with?(decl_file)
|
@@ -61,7 +61,6 @@ class T::Props::Decorator
|
|
61
61
|
VALID_RULE_KEYS = T.let(%i[
|
62
62
|
enum
|
63
63
|
foreign
|
64
|
-
foreign_hint_only
|
65
64
|
ifunset
|
66
65
|
immutable
|
67
66
|
override
|
@@ -359,12 +358,7 @@ class T::Props::Decorator
|
|
359
358
|
# get at the property (e.g., Chalk::ODM::Document exposes `get` and `set`).
|
360
359
|
define_getter_and_setter(name, rules) unless rules[:without_accessors]
|
361
360
|
|
362
|
-
if rules[:foreign] && rules[:foreign_hint_only]
|
363
|
-
raise ArgumentError.new(":foreign and :foreign_hint_only are mutually exclusive.")
|
364
|
-
end
|
365
|
-
|
366
361
|
handle_foreign_option(name, cls, rules, rules[:foreign]) if rules[:foreign]
|
367
|
-
handle_foreign_hint_only_option(name, cls, rules[:foreign_hint_only]) if rules[:foreign_hint_only]
|
368
362
|
handle_redaction_option(name, rules[:redaction]) if rules[:redaction]
|
369
363
|
end
|
370
364
|
|
@@ -484,42 +478,6 @@ class T::Props::Decorator
|
|
484
478
|
end
|
485
479
|
end
|
486
480
|
|
487
|
-
sig do
|
488
|
-
params(
|
489
|
-
prop_name: Symbol,
|
490
|
-
prop_cls: Module,
|
491
|
-
foreign_hint_only: T.untyped,
|
492
|
-
)
|
493
|
-
.void
|
494
|
-
end
|
495
|
-
private def handle_foreign_hint_only_option(prop_name, prop_cls, foreign_hint_only)
|
496
|
-
if ![String, Array].include?(prop_cls) && !prop_cls.is_a?(T::Props::CustomType)
|
497
|
-
raise ArgumentError.new(
|
498
|
-
"`foreign_hint_only` can only be used with String or Array prop types"
|
499
|
-
)
|
500
|
-
end
|
501
|
-
|
502
|
-
validate_foreign_option(
|
503
|
-
:foreign_hint_only, foreign_hint_only,
|
504
|
-
valid_type_msg: "an individual or array of a model class, or a Proc returning such."
|
505
|
-
)
|
506
|
-
|
507
|
-
unless foreign_hint_only.is_a?(Proc)
|
508
|
-
T::Configuration.soft_assert_handler(<<~MESSAGE, storytime: {prop: prop_name, value: foreign_hint_only}, notify: 'jerry')
|
509
|
-
Please use a Proc that returns a model class instead of the model class itself as the argument to `foreign_hint_only`. In other words:
|
510
|
-
|
511
|
-
instead of `prop :foo, String, foreign_hint_only: FooModel`
|
512
|
-
use `prop :foo, String, foreign_hint_only: -> {FooModel}`
|
513
|
-
|
514
|
-
OR
|
515
|
-
|
516
|
-
instead of `prop :foo, String, foreign_hint_only: [FooModel, BarModel]`
|
517
|
-
use `prop :foo, String, foreign_hint_only: -> {[FooModel, BarModel]}`
|
518
|
-
|
519
|
-
MESSAGE
|
520
|
-
end
|
521
|
-
end
|
522
|
-
|
523
481
|
# checked(:never) - Rules hash is expensive to check
|
524
482
|
sig do
|
525
483
|
params(
|
@@ -598,8 +556,8 @@ class T::Props::Decorator
|
|
598
556
|
# keep them from being lurky performance hits by issuing a bunch of un-batched DB queries.
|
599
557
|
# We could potentially address that by porting over something like AmbiguousIDLoader.
|
600
558
|
raise ArgumentError.new(
|
601
|
-
"Using an array for `foreign` is no longer supported. Instead, use
|
602
|
-
"
|
559
|
+
"Using an array for `foreign` is no longer supported. Instead, please use a union type of " \
|
560
|
+
"token types for the prop type, e.g., T.any(Opus::Autogen::Tokens::FooModelToken, Opus::Autogen::Tokens::BarModelToken)"
|
603
561
|
)
|
604
562
|
end
|
605
563
|
|
data/lib/types/types/base.rb
CHANGED
@@ -133,7 +133,7 @@ module T::Types
|
|
133
133
|
if valid?(obj)
|
134
134
|
nil
|
135
135
|
else
|
136
|
-
|
136
|
+
error_message(obj)
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
@@ -141,10 +141,14 @@ module T::Types
|
|
141
141
|
if recursively_valid?(obj)
|
142
142
|
nil
|
143
143
|
else
|
144
|
-
|
144
|
+
error_message(obj)
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
+
private def error_message(obj)
|
149
|
+
"Expected type #{self.name}, got #{describe_obj(obj)}"
|
150
|
+
end
|
151
|
+
|
148
152
|
def validate!(obj)
|
149
153
|
err = error_message_for_obj(obj)
|
150
154
|
raise TypeError.new(err) if err
|
data/lib/types/types/simple.rb
CHANGED
@@ -34,6 +34,23 @@ module T::Types
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
# overrides Base
|
38
|
+
private def error_message(obj)
|
39
|
+
error_message = super(obj)
|
40
|
+
actual_name = obj.class.name
|
41
|
+
|
42
|
+
return error_message unless name == actual_name
|
43
|
+
|
44
|
+
<<~MSG.strip
|
45
|
+
#{error_message}
|
46
|
+
|
47
|
+
The expected type and received object type have the same name but refer to different constants.
|
48
|
+
Expected type is #{name} with object id #{@raw_type.__id__}, but received type is #{actual_name} with object id #{obj.class.__id__}.
|
49
|
+
|
50
|
+
There might be a constant reloading problem in your application.
|
51
|
+
MSG
|
52
|
+
end
|
53
|
+
|
37
54
|
def to_nilable
|
38
55
|
@nilable ||= T::Types::Union.new([self, T::Utils::Nilable::NIL_TYPE])
|
39
56
|
end
|
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.9291
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stripe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|