sorbet-runtime 0.5.6223 → 0.5.6249

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: e4965b0c556acb24bfe27316314910f4439226de05f4958f08438d92ab3854ed
4
- data.tar.gz: 5ac1bb6baaf1e96d8d010924f0b0b8916807bf50a6009cdba4d605eceb41ac2c
3
+ metadata.gz: 836a1fbf0f8401ea225ae5124205ba0cdcfccab4164ab3b1e342bf285d7ea19b
4
+ data.tar.gz: 8758dcc34d96534830fc097a269d45c307f6841a9f20643c633be33eca142816
5
5
  SHA512:
6
- metadata.gz: 24272d365d1295e5edd880fa4f3f984191cca6e6f29431cc8c20d8531fa811df1f328533b16f2784c7cba6e2460e4c7e0276ca1e3c240a54234661d39d7e1abf
7
- data.tar.gz: 7ac8f9af520dca8a514678db4b08c4b89d8366e98b8c57be053494128f0c82e585a35e7355ac5d037d3e3d07e063885921a5ac86dbc53804841c694201491ed8
6
+ metadata.gz: 54ad13d894a1a35e28735d4e20f785e8cee486c8acf2786587639c1084ad2a881c36e0e3b8799553fb9fcc73bb7354fb085cd59402a83ff4259c7a0ef34fc935
7
+ data.tar.gz: 854336ccb394ab1524e171a29f130227dfc1cc8d8cf72b1ce6453c4c2a773d9e1ecd02393b0084eca6e6cdd1e9b5c5d999305c48bee051902b917ab754b07988
@@ -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]
@@ -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.6223
4
+ version: 0.5.6249
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-20 00:00:00.000000000 Z
11
+ date: 2021-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest