sorbet-runtime 0.5.9266 → 0.5.9287

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3b59f0bc1a270f595e0bd7d199c528af1fc3ed0dd81120185509533877b585b
4
- data.tar.gz: 926079130346393f975d6ccfa78cec361e4d4331ad58444fdc48e39a8d17a0c3
3
+ metadata.gz: 53cf2740a5d62c687f1c05148c6e59546c1a0250b706a960e0e1ca998dd9c917
4
+ data.tar.gz: c607bcf2b4cf9382f15c4274f963bc1033a8dad286b278551a7fb52a84f4b22c
5
5
  SHA512:
6
- metadata.gz: d21a28864aad2f3cda6e1d0bb1a5dfc08e9cd48df4d8539c3129ef5fb6e7add1611e373fa4564369362c400eb742fb325978fd792e1a4dfee8e846711fb889e4
7
- data.tar.gz: 5092f6320ada939fec4869e1f36530ac269bf7bee265733cfb0c85bf421e07b839618c9f5848b770537a2308bff8d9275c4eba3aae6ab3da0cfd3e7d90fa6a03
6
+ metadata.gz: 7bc3a0dc930e6f8689e041cdc129532607bc295395d190e35d15b6aff494ec9efb98a2d993042eaca6c2d1a6445ba2d5c51c1e44599837dfd39ed7cf2ba3cc98
7
+ data.tar.gz: 29982ffa0238b6aa91dd653d54d4bead28fb2f99ede5bac9826e758b99e6ce50e0f0f78777ab88235e8209c01c4d8ad71aae2e1a48eef514f0aa33b035e32616
@@ -3,11 +3,11 @@
3
3
 
4
4
  module T::Private::Sealed
5
5
  module NoInherit
6
- def inherited(other)
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 << other
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(other)
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 << other
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(other)
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 << other
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 || !decl_file
76
- raise "Couldn't determine enough file information for checking sealed modules"
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 `foreign_hint_only` " \
602
- "with an array or a Proc that returns an array, e.g., foreign_hint_only: -> {[Foo, Bar]}"
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
 
@@ -133,7 +133,7 @@ module T::Types
133
133
  if valid?(obj)
134
134
  nil
135
135
  else
136
- "Expected type #{self.name}, got #{describe_obj(obj)}"
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
- "Expected type #{self.name}, got #{describe_obj(obj)}"
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
@@ -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.9266
4
+ version: 0.5.9287
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-24 00:00:00.000000000 Z
11
+ date: 2021-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest