sorbet-runtime 0.4.4331 → 0.4.4355

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
  SHA1:
3
- metadata.gz: 23fe6d1adf71c97852b2e1bd12133d79212b7855
4
- data.tar.gz: f4ba79a25eb179f3aeba3a0c758876c363a3dc3c
3
+ metadata.gz: c20d0628aa85a684b88e4737a8e717fe91a7f15d
4
+ data.tar.gz: a5af90068a95344d3beeac78c6ad8d3ba334ad88
5
5
  SHA512:
6
- metadata.gz: cec9cff7dcb4ef500914a038bf009180436bdecb607d6eedbf2c6692a6267360f8b0c48e90b5cd70c0b667761d6ad2db4e8e583bdd40bdb16043bc1122d45e23
7
- data.tar.gz: b9dda89def4e0ea5e5dd33e4393b93999a8226f788a9080a5ffbd689df880990ec290e01c843fcf7eee336c6ec466984811cb0d32abc21cad03fe2a635bd6880
6
+ metadata.gz: 85dd318b56ab855f315742cbd5e3ea380990aa6a377be7d6fee40f0ac7fa5ac8f388abfb51fa0b2aea8af0c89c7df15857983bd3c799f281ccf7b20557832c4b
7
+ data.tar.gz: 3f8f068484b137a255cf122a5e94c36799410d4207f352e6ba881d7cd1d58b9f11d2f7b52a6f32cee52fa41cd69c40d2fa60f0cec75c538582c01e39e5a476d0
data/lib/types/_types.rb CHANGED
@@ -178,6 +178,9 @@ module T
178
178
  #
179
179
  # sig {params(arg: T.nilable(A), msg: T.nilable(String)).returns(A)}
180
180
  def self.must(arg, msg=nil)
181
+ return arg if arg
182
+ return arg if arg == false
183
+
181
184
  begin
182
185
  if msg
183
186
  if !T.unsafe(msg).is_a?(String)
@@ -186,11 +189,9 @@ module T
186
189
  else
187
190
  msg = "Passed `nil` into T.must"
188
191
  end
189
- raise TypeError.new(msg) if arg.nil?
190
- arg
192
+ raise TypeError.new(msg)
191
193
  rescue TypeError => e # raise into rescue to ensure e.backtrace is populated
192
194
  T::Private::ErrorHandler.handle_inline_type_error(e)
193
- arg
194
195
  end
195
196
  end
196
197
 
@@ -175,14 +175,7 @@ module T::Configuration
175
175
  end
176
176
 
177
177
  private_class_method def self.call_validation_error_handler_default(signature, opts)
178
- method_file, method_line = signature.method.source_location
179
- location = opts[:location]
180
-
181
- error_message = "#{opts[:kind]}#{opts[:name] ? " '#{opts[:name]}'" : ''}: #{opts[:message]}\n" \
182
- "Caller: #{location.path}:#{location.lineno}\n" \
183
- "Definition: #{method_file}:#{method_line}"
184
-
185
- raise TypeError.new(error_message)
178
+ raise TypeError.new(opts[:pretty_message])
186
179
  end
187
180
 
188
181
  def self.call_validation_error_handler(signature, opts)
@@ -1150,10 +1150,16 @@ module T::Private::Methods::CallValidation
1150
1150
  def self.report_error(method_sig, error_message, kind, name, type, value, caller_offset: 0)
1151
1151
  method_sig.mark_failed
1152
1152
  caller_loc = T.must(caller_locations(3 + caller_offset, 1))[0]
1153
+ definition_file, definition_line = method_sig.method.source_location
1154
+
1155
+ pretty_message = "#{kind}#{name ? " '#{name}'" : ''}: #{error_message}\n" \
1156
+ "Caller: #{caller_loc.path}:#{caller_loc.lineno}\n" \
1157
+ "Definition: #{definition_file}:#{definition_line}"
1153
1158
 
1154
1159
  T::Private::ErrorHandler.handle_call_validation_error(
1155
1160
  method_sig,
1156
1161
  message: error_message,
1162
+ pretty_message: pretty_message,
1157
1163
  kind: kind,
1158
1164
  name: name,
1159
1165
  type: type,
@@ -131,9 +131,6 @@ module T::Private::Methods
131
131
  end
132
132
 
133
133
  def generated
134
- if T.unsafe(true)
135
- raise "The .generated API is unstable, so we don't want it used until we redesign it. To change Sorbet's runtime behavior, see https://sorbet.org/docs/tconfiguration"
136
- end
137
134
  check_live!
138
135
 
139
136
  if !decl.generated.equal?(ARG_NOT_PROVIDED)
@@ -2,35 +2,23 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  #
5
- # Hey there!
5
+ # From the static system, T::Utils::RuntimeProfiled is T.untyped.
6
6
  #
7
- # T::Utils::Runtime is just a random class. Chances are[^1] it's not a class
8
- # that your variables are instances of, which means that using it in a type
9
- # signature will always create a type error.
7
+ # But from the runtime system, it's a random class (specifically, a class that
8
+ # normal programs currently don't have any instances of).
10
9
  #
11
- # At first, it doesn't seem like a good thing to have a type that's sole
12
- # purpose is to cause type errors. The trick is that within the ruby-types
13
- # team, we only use T::Utils::RuntimeProfiled within 'generated' sigs.
10
+ # Thus, T::Utils::RuntimeProfiled can be used to introduce runtime-only type
11
+ # errors. This seems like a bad idea, but it's not. It can be used to gather
12
+ # runtime type information from running code via a custom T::Configuration
13
+ # handler.
14
14
  #
15
- # Unlike normal sigs, generated sigs never raise at runtime. They also log the
16
- # actual, observed type on type error to a central location. We're using these
17
- # observed types to refine and expand our type coverage in pay-server.
15
+ # This process has only ever been used at Stripe, and is likely to have rough
16
+ # edges. If you've managed to find your way here and you're curious to try it,
17
+ # please chat with us on Slack. There are no docs.
18
18
  #
19
- # What does this all mean for you?
20
- #
21
- # - If you were just curious, that's it! Leave the sig as is, and carry on.
22
- # - If you wanted to replace this sig with a better, hand-authored one:
23
- #
24
- # 1. Remove 'generated' from the sig.
25
- # 2. Update the sig to your liking
26
- #
27
- # Questions? :portal-to: => #ruby-types
28
- #
29
- # [^1]: Unless you happen to be calling T::Utils::RuntimeProfiled.new directly...
19
+ # See also: the --suggest-runtime-profiled flag to sorbet.
30
20
  #
31
21
 
32
22
  module T; end
33
23
  module T::Utils; end
34
- # Sorbet guesses this type instead of T.untyped when passed --suggest-runtime-profiled
35
-
36
24
  class T::Utils::RuntimeProfiled; 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.4.4331
4
+ version: 0.4.4355
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-27 00:00:00.000000000 Z
11
+ date: 2019-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest