sorbet-runtime 0.5.6229 → 0.5.6257

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: b502e1602055bd3d9f75671c0261e4dd1544aa4faefd5750bdff385843cfbac9
4
- data.tar.gz: 2b9b067b20641e5a881c8e14350053a6a63578a5abd956f2bd6b072914f804c5
3
+ metadata.gz: 2869f8c9854f5900c8321d756b478077af3d9656b932bb3b31d3ffe180c00ee4
4
+ data.tar.gz: f844a05089620d58a2fbbf6fd33445502efb6d3d5395044b2c0bf1b03c868741
5
5
  SHA512:
6
- metadata.gz: 3cdff26a4225bef4e61323f4b7b45d5866585af11309ec1ffe34175b387aa35f76e1f26150cc59db28d7f55958e90bf91820070c11b779341e1895cbbaf7e8f5
7
- data.tar.gz: 0032ed7d97c722066dedfbb790a3c45edf8ba03942ebd2c513b0aefcb4b78dc24f3b4982f649a424774a0ba0e9e9a8aae2d4279c82462962a4786f4ce948acca
6
+ metadata.gz: 233e4afe3e043ab5c6098eb6c75876882169568800f7cc8fc8e103a97bb776be20ad556541a99589e65c0c5d5af061f14aceb0daaf08762e7316096d4c6432d3
7
+ data.tar.gz: eab9556baf8e777ac6983bfd0ab57d7ce1c38a94a1a10401d5d0d393f1aa8fba47e52b330562dfa2f1bd6dfc1db21d900249f5aa31647f94059e8719b54ea4b0
@@ -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).
@@ -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
@@ -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
@@ -99,21 +99,18 @@ module T::Props
99
99
  else
100
100
  "#{varname}.nil? ? nil : #{inner}"
101
101
  end
102
+ elsif type.types.all? {|t| generate(t, mode, varname).nil?}
103
+ # Handle, e.g., T::Boolean
104
+ nil
102
105
  else
103
- inners = type.types.map {|t| generate(t, mode, varname)}.uniq
104
- if inners.length <= 1
105
- # Handle, e.g., T::Boolean
106
- inners.first
107
- else
108
- # We currently deep_clone_object if the type was T.any(Integer, Float).
109
- # When we get better support for union types (maybe this specific
110
- # union type, because it would be a replacement for
111
- # Chalk::ODM::DeprecatedNumemric), we could opt to special case
112
- # this union to have no specific serde transform (the only reason
113
- # why Float has a special case is because round tripping through
114
- # JSON might normalize Floats to Integers)
115
- "T::Props::Utils.deep_clone_object(#{varname})"
116
- end
106
+ # We currently deep_clone_object if the type was T.any(Integer, Float).
107
+ # When we get better support for union types (maybe this specific
108
+ # union type, because it would be a replacement for
109
+ # Chalk::ODM::DeprecatedNumemric), we could opt to special case
110
+ # this union to have no specific serde transform (the only reason
111
+ # why Float has a special case is because round tripping through
112
+ # JSON might normalize Floats to Integers)
113
+ "T::Props::Utils.deep_clone_object(#{varname})"
117
114
  end
118
115
  when T::Types::Intersection
119
116
  dynamic_fallback = "T::Props::Utils.deep_clone_object(#{varname})"
@@ -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
@@ -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.6229
4
+ version: 0.5.6257
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-22 00:00:00.000000000 Z
11
+ date: 2021-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest