sorbet-runtime 0.5.6189 → 0.5.6277

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: '078455e4f5dfee05efee1b1dc5283a572d80e4583699ef18fbd51cc606c1a559'
4
- data.tar.gz: 6d77cb7b423ae756a33c04e15a50ff0d7d17a0cbd0e25460c0ce89b25959fa97
3
+ metadata.gz: 22707230a23f48bfd62933d0a85920876e2ac38dc8b78c3306d205c8247e0c69
4
+ data.tar.gz: e5c3afa7f8dc8eb5dab01edd0086062c0597306ddd5a985b4ddde0da5e9c5a9f
5
5
  SHA512:
6
- metadata.gz: 171c564c0b615d126fa8e14bff2dc5567baa53a2c0d702032f8971fd4f83e1cd3c3d888e4c4ac0e9843e0b516fe1563807cd6d8afcb9d8c0dfa15da28ff8758d
7
- data.tar.gz: 967a1bb33ed88e50c31bf01dbbfdaad43e7ef7f66723c5648a58bc47d19cb5f5c46b7fd9a3733310cc07eb72743d32bb80341aa7e3f529ea5584def01195591e
6
+ metadata.gz: cd1d3b58bf2c258db84c6abffedd63c406bc4145f9484265a7ad988eb73dab15f0fb3186b880461ce810eb5cad494fd07fcca381694fc13d9826bd9711bdbd1b
7
+ data.tar.gz: d7ea87fcf45c0995cf0d14551ab8ad30441d6fcd43375f27e53b529b129180dd5c9a34b31db56e4994eaa8ce762fb25148fb24540f1b6a280df02e91ab77d6ee
@@ -412,6 +412,32 @@ module T::Configuration
412
412
  @module_name_mangler = handler
413
413
  end
414
414
 
415
+ # Set to a PII handler function. This will be called with the `sensitivity:`
416
+ # annotations on things that use `T::Props` and can modify them ahead-of-time.
417
+ #
418
+ # @param [Lambda, Proc, nil] value Proc that takes a hash mapping symbols to the
419
+ # prop values. Pass nil to avoid changing `sensitivity:` annotations.
420
+ def self.normalize_sensitivity_and_pii_handler=(handler)
421
+ @sensitivity_and_pii_handler = handler
422
+ end
423
+
424
+ def self.normalize_sensitivity_and_pii_handler
425
+ @sensitivity_and_pii_handler
426
+ end
427
+
428
+ # Set to a function which can get the 'owner' of a class. This is
429
+ # used in reporting deserialization errors
430
+ #
431
+ # @param [Lambda, Proc, nil] value Proc that takes a class and
432
+ # produces its owner, or `nil` if it does not have one.
433
+ def self.class_owner_finder=(handler)
434
+ @class_owner_finder = handler
435
+ end
436
+
437
+ def self.class_owner_finder
438
+ @class_owner_finder
439
+ end
440
+
415
441
  # Temporarily disable ruby warnings while executing the given block. This is
416
442
  # useful when doing something that would normally cause a warning to be
417
443
  # emitted in Ruby verbose mode ($VERBOSE = true).
data/lib/types/helpers.rb CHANGED
@@ -33,7 +33,7 @@ module T::Helpers
33
33
  # end
34
34
  #
35
35
  # Except that it is statically analyzed by sorbet.
36
- def mixes_in_class_methods(mod)
37
- Private::Mixins.declare_mixes_in_class_methods(self, mod)
36
+ def mixes_in_class_methods(mod, *mods)
37
+ Private::Mixins.declare_mixes_in_class_methods(self, [mod].concat(mods))
38
38
  end
39
39
  end
@@ -75,40 +75,6 @@ module T::Private::Methods
75
75
  T::Types::Proc.new(decl.params, decl.returns)
76
76
  end
77
77
 
78
- # See docs at T::Utils.register_forwarder.
79
- def self.register_forwarder(from_method, to_method, mode: Modes.overridable, remove_first_param: false)
80
- # Normalize the method (see comment in signature_for_key).
81
- from_method = from_method.owner.instance_method(from_method.name)
82
-
83
- from_key = method_to_key(from_method)
84
- maybe_run_sig_block_for_key(from_key)
85
- if @signatures_by_method.key?(from_key)
86
- raise "#{from_method} already has a method signature"
87
- end
88
-
89
- from_params = from_method.parameters
90
- if from_params.length != 2 || from_params[0][0] != :rest || from_params[1][0] != :block
91
- raise "forwarder methods should take a single splat param and a block param. `#{from_method}` " \
92
- "takes these params: #{from_params}. For help, ask #dev-productivity."
93
- end
94
-
95
- # If there's already a signature for to_method, we get `parameters` from there, to enable
96
- # chained forwarding. NB: we don't use `signature_for_key` here, because the normalization it
97
- # does is broken when `to_method` has been clobbered by another method.
98
- to_key = method_to_key(to_method)
99
- maybe_run_sig_block_for_key(to_key)
100
- to_params = @signatures_by_method[to_key]&.parameters || to_method.parameters
101
-
102
- if remove_first_param
103
- to_params = to_params[1..-1]
104
- end
105
-
106
- # We don't bother trying to preserve any types from to_signature because this won't be
107
- # statically analyzed, and the types will just get checked when the forwarding happens.
108
- from_signature = Signature.new_untyped(method: from_method, mode: mode, parameters: to_params)
109
- @signatures_by_method[from_key] = from_signature
110
- end
111
-
112
78
  # Returns the signature for a method whose definition was preceded by `sig`.
113
79
  #
114
80
  # @param method [UnboundMethod]
@@ -11,6 +11,10 @@ class T::Private::Methods::Signature
11
11
  # Using `Untyped` ensures we'll get an error if we ever try validation on these.
12
12
  not_typed = T::Private::Types::NotTyped.new
13
13
  raw_return_type = not_typed
14
+ # Map missing parameter names to "argN" positionally
15
+ parameters = parameters.each_with_index.map do |(param_kind, param_name), index|
16
+ [param_kind, param_name || "arg#{index}"]
17
+ end
14
18
  raw_arg_types = parameters.map do |_param_kind, param_name|
15
19
  [param_name, not_typed]
16
20
  end.to_h
@@ -4,8 +4,8 @@
4
4
  module T::Private
5
5
  module MixesInClassMethods
6
6
  def included(other)
7
- mod = Abstract::Data.get(self, :class_methods_mixin)
8
- other.extend(mod)
7
+ mods = Abstract::Data.get(self, :class_methods_mixins)
8
+ mods.each {|mod| other.extend(mod)}
9
9
  super
10
10
  end
11
11
  end
@@ -16,12 +16,12 @@ module T::Private
16
16
  raise "Classes cannot be used as mixins, and so mixes_in_class_methods cannot be used on a Class."
17
17
  end
18
18
 
19
- if Abstract::Data.key?(mixin, :class_methods_mixin)
20
- raise "mixes_in_class_methods can only be used once per module."
19
+ if Abstract::Data.key?(mixin, :class_methods_mixins)
20
+ class_methods = Abstract::Data.get(mixin, :class_methods_mixins) + class_methods
21
21
  end
22
22
 
23
23
  mixin.singleton_class.include(MixesInClassMethods)
24
- Abstract::Data.set(mixin, :class_methods_mixin, class_methods)
24
+ Abstract::Data.set(mixin, :class_methods_mixins, class_methods)
25
25
  end
26
26
  end
27
27
  end
@@ -100,6 +100,7 @@ module T::Props
100
100
  # form.
101
101
  #
102
102
  # @return [void]
103
+ sig {params(name: Symbol, cls: T.untyped, rules: T.untyped).void}
103
104
  def prop(name, cls, rules={})
104
105
  cls = T::Utils.coerce(cls) if !cls.is_a?(Module)
105
106
  decorator.prop_defined(name, cls, rules)
@@ -124,7 +125,7 @@ module T::Props
124
125
  end
125
126
 
126
127
  # Shorthand helper to define a `prop` with `immutable => true`
127
- sig {params(name: T.any(Symbol, String), cls_or_args: T.untyped, args: T::Hash[Symbol, T.untyped]).void}
128
+ sig {params(name: Symbol, cls_or_args: T.untyped, args: T::Hash[Symbol, T.untyped]).void}
128
129
  def const(name, cls_or_args, args={})
129
130
  if (cls_or_args.is_a?(Hash) && cls_or_args.key?(:immutable)) || args.key?(:immutable)
130
131
  Kernel.raise ArgumentError.new("Cannot pass 'immutable' argument when using 'const' keyword to define a prop")
@@ -306,8 +306,9 @@ class T::Props::Decorator
306
306
  type = T::Utils::Nilable.get_underlying_type(type)
307
307
 
308
308
  sensitivity_and_pii = {sensitivity: rules[:sensitivity]}
309
- if defined?(Opus) && defined?(Opus::Sensitivity) && defined?(Opus::Sensitivity::Utils)
310
- sensitivity_and_pii = Opus::Sensitivity::Utils.normalize_sensitivity_and_pii_annotation(sensitivity_and_pii)
309
+ normalize = T::Configuration.normalize_sensitivity_and_pii_handler
310
+ if normalize
311
+ sensitivity_and_pii = normalize.call(sensitivity_and_pii)
311
312
 
312
313
  # We check for Class so this is only applied on concrete
313
314
  # documents/models; We allow mixins containing props to not
@@ -246,11 +246,11 @@ module T::Props::Serializable::DecoratorMethods
246
246
 
247
247
  # Notify the model owner if it exists, and always notify the API owner.
248
248
  begin
249
- if defined?(Opus) && defined?(Opus::Ownership) && decorated_class < Opus::Ownership
249
+ if T::Configuration.class_owner_finder && (owner = T::Configuration.class_owner_finder.call(decorated_class))
250
250
  T::Configuration.hard_assert_handler(
251
251
  msg,
252
252
  storytime: storytime,
253
- project: decorated_class.get_owner
253
+ project: owner
254
254
  )
255
255
  end
256
256
  ensure
data/lib/types/utils.rb CHANGED
@@ -52,19 +52,6 @@ module T::Utils
52
52
  end.uniq
53
53
  end
54
54
 
55
- # Associates a signature with a forwarder method that matches the signature of the method it
56
- # forwards to. This is necessary because forwarder methods are often declared with catch-all
57
- # splat parameters, rather than the exact set of parameters ultimately used by the target method,
58
- # so they cannot be validated as strictly.
59
- #
60
- # The caller of this method must ensure that the forwarder method properly forwards all parameters
61
- # such that the signature is accurate.
62
- def self.register_forwarder(from_method, to_method, remove_first_param: false)
63
- T::Private::Methods.register_forwarder(
64
- from_method, to_method, remove_first_param: remove_first_param
65
- )
66
- end
67
-
68
55
  # Returns the signature for the instance method on the supplied module, or nil if it's not found or not typed.
69
56
  #
70
57
  # @example T::Utils.signature_for_instance_method(MyClass, :my_method)
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.6189
4
+ version: 0.5.6277
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-26 00:00:00.000000000 Z
11
+ date: 2021-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest