sorbet-runtime 0.5.11190 → 0.5.11200

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 533fd9ec399ceffbb032f86c6b9b9a9e4efedb86dd0425bebaa471fc09036cdf
4
- data.tar.gz: ef0fcf828932347277f8833d285cc64812b4196363428a71eae019d351af98a4
3
+ metadata.gz: 03f7a85e5b0a63ac54fdd4f82cbfcf269484cf649bb1778006e0b41d3a800eba
4
+ data.tar.gz: b5b2f87adfd29488c1ad748de84c676a73903055f79a8d136f7300960dcc850b
5
5
  SHA512:
6
- metadata.gz: 1adb69699281832dbe6bfe654c7d71635654a59383f1825651d98edb809dc13f51746113b4d179d42fba0135943153cbe544b8d124f6020d7637df1bb50f9988
7
- data.tar.gz: fae00525324c43395367cfd8706729376a35badd76dbc89ff33ace7dfce758e02f837f5258384b6a5327209a25fd022d29b82dad7fabf9ea57b4635a930e6771
6
+ metadata.gz: 3d043f9735a22824b4c07d1130dbf0a6a9306dbe5005b7be487db8b5a4e53dba14b41e0cf8118e93de1ffafaa1d1fe8c2fd546eed426c4661e12745000152e3f
7
+ data.tar.gz: 8204b78b673773bb91ac61fa7079ad1a6552370825c5cff4130b5aa4e25bb18fdea397378f05918c861d50398cd75bd449d18795b3968d988c87bcf4e0fa47c6
@@ -73,7 +73,6 @@ require_relative 'types/private/abstract/validate'
73
73
 
74
74
  # Catch all. Sort of built by `cd extn; find types -type f | grep -v test | sort`
75
75
  require_relative 'types/generic'
76
- require_relative 'types/interface_wrapper'
77
76
  require_relative 'types/private/abstract/declare'
78
77
  require_relative 'types/private/abstract/hooks'
79
78
  require_relative 'types/private/casts'
@@ -18,7 +18,6 @@ module T::Private::Abstract::Declare
18
18
  Abstract::Data.set(mod, :abstract_type, type)
19
19
 
20
20
  mod.extend(Abstract::Hooks)
21
- mod.extend(T::InterfaceWrapper::Helpers)
22
21
 
23
22
  if mod.is_a?(Class)
24
23
  if type == :interface
@@ -183,7 +183,7 @@ module T::Private::Methods
183
183
  self
184
184
  end
185
185
 
186
- # Declares valid type paramaters which can be used with `T.type_parameter` in
186
+ # Declares valid type parameters which can be used with `T.type_parameter` in
187
187
  # this `sig`.
188
188
  #
189
189
  # This is used for generic methods. Example usage:
@@ -332,7 +332,7 @@ class T::Props::Decorator
332
332
 
333
333
  prop_validate_definition!(name, cls, rules, type_object)
334
334
 
335
- # Retrive the possible underlying object with T.nilable.
335
+ # Retrieve the possible underlying object with T.nilable.
336
336
  type = T::Utils::Nilable.get_underlying_type(type)
337
337
 
338
338
  rules_sensitivity = rules[:sensitivity]
@@ -54,7 +54,7 @@ module T::Types
54
54
  value_type = types[1]
55
55
  obj.each_pair do |key, val|
56
56
  # Some objects (I'm looking at you Rack::Utils::HeaderHash) don't
57
- # iterate over a [key, value] array, so we can't juse use the type.recursively_valid?(v)
57
+ # iterate over a [key, value] array, so we can't just use the type.recursively_valid?(v)
58
58
  return false if !key_type.recursively_valid?(key) || !value_type.recursively_valid?(val)
59
59
  end
60
60
  true
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.11190
4
+ version: 0.5.11200
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-12 00:00:00.000000000 Z
11
+ date: 2024-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -165,7 +165,6 @@ files:
165
165
  - lib/types/enum.rb
166
166
  - lib/types/generic.rb
167
167
  - lib/types/helpers.rb
168
- - lib/types/interface_wrapper.rb
169
168
  - lib/types/non_forcing_constants.rb
170
169
  - lib/types/private/abstract/data.rb
171
170
  - lib/types/private/abstract/declare.rb
@@ -1,162 +0,0 @@
1
- # frozen_string_literal: true
2
- # typed: false
3
-
4
- # Wraps an object, exposing only the methods defined on a given class/module. The idea is that, in
5
- # the absence of a static type checker that would prevent you from calling non-Bar methods on a
6
- # variable of type Bar, we can use these wrappers as a way of enforcing it at runtime.
7
- #
8
- # Once we ship static type checking, we should get rid of this entirely.
9
- class T::InterfaceWrapper
10
- extend T::Sig
11
-
12
- module Helpers
13
- def wrap_instance(obj)
14
- T::InterfaceWrapper.wrap_instance(obj, self)
15
- end
16
-
17
- def wrap_instances(arr)
18
- T::InterfaceWrapper.wrap_instances(arr, self)
19
- end
20
- end
21
-
22
- private_class_method :new # use `wrap_instance`
23
-
24
- def self.wrap_instance(obj, interface_mod)
25
- wrapper = wrapped_dynamic_cast(obj, interface_mod)
26
- if wrapper.nil?
27
- raise "#{obj.class} cannot be cast to #{interface_mod}"
28
- end
29
- wrapper
30
- end
31
-
32
- sig do
33
- params(
34
- arr: Array,
35
- interface_mod: T.untyped
36
- )
37
- .returns(Array)
38
- end
39
- def self.wrap_instances(arr, interface_mod)
40
- arr.map {|instance| self.wrap_instance(instance, interface_mod)}
41
- end
42
-
43
- def initialize(target_obj, interface_mod)
44
- if target_obj.is_a?(T::InterfaceWrapper)
45
- # wrapped_dynamic_cast should guarantee this never happens.
46
- raise "Unexpected: wrapping a wrapper. Please report this bug at https://github.com/sorbet/sorbet/issues"
47
- end
48
-
49
- if !target_obj.is_a?(interface_mod)
50
- # wrapped_dynamic_cast should guarantee this never happens.
51
- raise "Unexpected: `is_a?` failed. Please report this bug at https://github.com/sorbet/sorbet/issues"
52
- end
53
-
54
- if target_obj.class == interface_mod
55
- # wrapped_dynamic_cast should guarantee this never happens.
56
- raise "Unexpected: exact class match. Please report this bug at https://github.com/sorbet/sorbet/issues"
57
- end
58
-
59
- @target_obj = target_obj
60
- @interface_mod = interface_mod
61
- self_methods = self.class.self_methods
62
-
63
- # If perf becomes an issue, we can define these on an anonymous subclass, and keep a cache
64
- # so we only need to do it once per unique `interface_mod`
65
- T::Utils.methods_excluding_object(interface_mod).each do |method_name|
66
- if self_methods.include?(method_name)
67
- raise "interface_mod has a method that conflicts with #{self.class}: #{method_name}"
68
- end
69
-
70
- define_singleton_method(method_name) do |*args, &blk|
71
- target_obj.send(method_name, *args, &blk)
72
- end
73
-
74
- if singleton_class.respond_to?(:ruby2_keywords, true)
75
- singleton_class.send(:ruby2_keywords, method_name)
76
- end
77
-
78
- if target_obj.singleton_class.public_method_defined?(method_name)
79
- # no-op, it's already public
80
- elsif target_obj.singleton_class.protected_method_defined?(method_name)
81
- singleton_class.send(:protected, method_name)
82
- elsif target_obj.singleton_class.private_method_defined?(method_name)
83
- singleton_class.send(:private, method_name)
84
- else
85
- raise "This should never happen. Report this bug at https://github.com/sorbet/sorbet/issues"
86
- end
87
- end
88
- end
89
-
90
- def kind_of?(other)
91
- is_a?(other)
92
- end
93
-
94
- def is_a?(other)
95
- if !other.is_a?(Module)
96
- raise TypeError.new("class or module required")
97
- end
98
-
99
- # This makes is_a? return true for T::InterfaceWrapper (and its ancestors),
100
- # as well as for @interface_mod and its ancestors.
101
- self.class <= other || @interface_mod <= other
102
- end
103
-
104
- # Prefixed because we're polluting the namespace of the interface we're wrapping, and we don't
105
- # want anyone else (besides dynamic_cast) calling it.
106
- def __target_obj_DO_NOT_USE # rubocop:disable Naming/MethodName
107
- @target_obj
108
- end
109
-
110
- # Prefixed because we're polluting the namespace of the interface we're wrapping, and we don't
111
- # want anyone else (besides wrapped_dynamic_cast) calling it.
112
- def __interface_mod_DO_NOT_USE # rubocop:disable Naming/MethodName
113
- @interface_mod
114
- end
115
-
116
- # "Cast" an object to another type. If `obj` is an InterfaceWrapper, returns the the wrapped
117
- # object if that matches `type`. Otherwise, returns `obj` if it matches `type`. Otherwise,
118
- # returns nil.
119
- #
120
- # @param obj [Object] object to cast
121
- # @param mod [Module] type to cast `obj` to
122
- #
123
- # @example
124
- # if (impl = T::InterfaceWrapper.dynamic_cast(iface, MyImplementation))
125
- # impl.do_things
126
- # end
127
- def self.dynamic_cast(obj, mod)
128
- if obj.is_a?(T::InterfaceWrapper)
129
- target_obj = obj.__target_obj_DO_NOT_USE
130
- target_obj.is_a?(mod) ? target_obj : nil
131
- elsif obj.is_a?(mod)
132
- obj
133
- else
134
- nil
135
- end
136
- end
137
-
138
- # Like dynamic_cast, but puts the result in its own wrapper if necessary.
139
- #
140
- # @param obj [Object] object to cast
141
- # @param mod [Module] type to cast `obj` to
142
- def self.wrapped_dynamic_cast(obj, mod)
143
- # Avoid unwrapping and creating an equivalent wrapper.
144
- if obj.is_a?(T::InterfaceWrapper) && obj.__interface_mod_DO_NOT_USE == mod
145
- return obj
146
- end
147
-
148
- cast_obj = dynamic_cast(obj, mod)
149
- if cast_obj.nil?
150
- nil
151
- elsif cast_obj.class == mod
152
- # Nothing to wrap, they want the full class
153
- cast_obj
154
- else
155
- new(cast_obj, mod)
156
- end
157
- end
158
-
159
- def self.self_methods
160
- @self_methods ||= self.instance_methods(false).to_set
161
- end
162
- end