sorbet-runtime 0.5.10891 → 0.5.10894

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
  SHA256:
3
- metadata.gz: c7e6942650e54cd39050183984f52dc731e95f4bdd303ffda6ab23323e5ebd5c
4
- data.tar.gz: e5eeec1f6e2fa6628f6a81da6201285698f3847dc22e88baae7499c9792e46af
3
+ metadata.gz: e0e4ca50e40dba17d9e6525f9d45385b3e9323e1a0768501766dfaa16b55f50a
4
+ data.tar.gz: d10b11ea6372bbdb52e16f384d8ed10d47319aab9815f88f0cfa3d4facb435f0
5
5
  SHA512:
6
- metadata.gz: b56f40f9db44bf40ef55cafcfa391e24d39ae5a07f8e207854026b138fe7a81fc35e23124219b9f254fba9fa1548aa48ce9eececadb88606a92b5f8bb520ffa6
7
- data.tar.gz: 67f83387e862176599bfaf1dc2e3ea73fd9ae0bc326c4d0ede7d3404075e45c6b71df77e4cfd3961b9a1970831d571921fa8825af03eaa77d6fcbef3b0da4818
6
+ metadata.gz: 196f8cd6fcc9c7adb30db052111187c41c7f6ea85aae010cc48bc5ea0149a1cd496547be98bc2a308c6d8307633e253fc680eec1e0352d840829658ab231ac3e
7
+ data.tar.gz: deb86d5588fb3decdb5bb4826ebc0a2901b7b425cdeadfdb2f0436d92939c24978ca2004fbeb22459525dafd33e83a93ea0414cff23f691358407158819db9ae
@@ -91,10 +91,13 @@ module T::Private::ClassUtils
91
91
  end
92
92
 
93
93
  # Replaces a method, either by overwriting it (if it is defined directly on `mod`) or by
94
- # overriding it (if it is defined by one of mod's ancestors). Returns a ReplacedMethod instance
95
- # on which you can call `bind(...).call(...)` to call the original method, or `restore` to
96
- # restore the original method (by overwriting or removing the override).
97
- def self.replace_method(mod, name, &blk)
94
+ # overriding it (if it is defined by one of mod's ancestors). If `original_only` is
95
+ # false, returns a ReplacedMethod instance on which you can call `bind(...).call(...)`
96
+ # to call the original method, or `restore` to restore the original method (by
97
+ # overwriting or removing the override).
98
+ #
99
+ # If `original_only` is true, return the `UnboundMethod` representing the original method.
100
+ def self.replace_method(mod, name, original_only=false, &blk)
98
101
  original_method = mod.instance_method(name)
99
102
  original_visibility = visibility_method_name(mod, name)
100
103
  original_owner = original_method.owner
@@ -120,8 +123,12 @@ module T::Private::ClassUtils
120
123
  def_with_visibility(mod, name, original_visibility, &blk)
121
124
  end
122
125
  end
123
- new_method = mod.instance_method(name)
124
126
 
125
- ReplacedMethod.new(mod, original_method, new_method, overwritten, original_visibility)
127
+ if original_only
128
+ original_method
129
+ else
130
+ new_method = mod.instance_method(name)
131
+ ReplacedMethod.new(mod, original_method, new_method, overwritten, original_visibility)
132
+ end
126
133
  end
127
134
  end
@@ -252,7 +252,7 @@ module T::Private::Methods
252
252
  # (or unwrap back to the original method).
253
253
  key = method_owner_and_name_to_key(mod, method_name)
254
254
  unless current_declaration.raw
255
- T::Private::ClassUtils.replace_method(mod, method_name) do |*args, &blk|
255
+ T::Private::ClassUtils.replace_method(mod, method_name, true) do |*args, &blk|
256
256
  method_sig = T::Private::Methods.maybe_run_sig_block_for_key(key)
257
257
  method_sig ||= T::Private::Methods._handle_missing_method_signature(
258
258
  self,
@@ -501,19 +501,37 @@ module T::Private::Methods
501
501
  return
502
502
  end
503
503
  if is_enabled
504
- @old_hooks.each(&:restore)
504
+ # A cut-down version of T::Private::ClassUtils::ReplacedMethod#restore, because we
505
+ # should only be resetting final hooks during tests.
506
+ T::Configuration.without_ruby_warnings do
507
+ Module.define_method(:included, @old_hooks[0])
508
+ Module.define_method(:extended, @old_hooks[1])
509
+ Class.define_method(:inherited, @old_hooks[2])
510
+ end
505
511
  @old_hooks = nil
506
512
  else
507
- old_included = T::Private::ClassUtils.replace_method(Module, :included) do |arg|
508
- old_included.bind(self).call(arg)
513
+ old_included = T::Private::ClassUtils.replace_method(Module, :included, true) do |arg|
514
+ if T::Configuration::AT_LEAST_RUBY_2_7
515
+ old_included.bind_call(self, arg)
516
+ else
517
+ old_included.bind(self).call(arg)
518
+ end
509
519
  ::T::Private::Methods._hook_impl(arg, false, self)
510
520
  end
511
- old_extended = T::Private::ClassUtils.replace_method(Module, :extended) do |arg|
512
- old_extended.bind(self).call(arg)
521
+ old_extended = T::Private::ClassUtils.replace_method(Module, :extended, true) do |arg|
522
+ if T::Configuration::AT_LEAST_RUBY_2_7
523
+ old_extended.bind_call(self, arg)
524
+ else
525
+ old_extended.bind(self).call(arg)
526
+ end
513
527
  ::T::Private::Methods._hook_impl(arg, true, self)
514
528
  end
515
- old_inherited = T::Private::ClassUtils.replace_method(Class, :inherited) do |arg|
516
- old_inherited.bind(self).call(arg)
529
+ old_inherited = T::Private::ClassUtils.replace_method(Class, :inherited, true) do |arg|
530
+ if T::Configuration::AT_LEAST_RUBY_2_7
531
+ old_inherited.bind_call(self, arg)
532
+ else
533
+ old_inherited.bind(self).call(arg)
534
+ end
517
535
  ::T::Private::Methods._hook_impl(arg, false, self)
518
536
  end
519
537
  @old_hooks = [old_included, old_extended, old_inherited]
@@ -14,7 +14,7 @@ module T::Private::Methods::CallValidation
14
14
  def self.wrap_method_if_needed(mod, method_sig, original_method)
15
15
  original_visibility = visibility_method_name(mod, method_sig.method_name)
16
16
  if method_sig.mode == T::Private::Methods::Modes.abstract
17
- T::Private::ClassUtils.replace_method(mod, method_sig.method_name) do |*args, &blk|
17
+ T::Private::ClassUtils.replace_method(mod, method_sig.method_name, true) do |*args, &blk|
18
18
  # TODO: write a cop to ensure that abstract methods have an empty body
19
19
  #
20
20
  # We allow abstract methods to be implemented by things further down the ancestor chain.
data/lib/types/struct.rb CHANGED
@@ -10,7 +10,7 @@ end
10
10
  class T::Struct < T::InexactStruct
11
11
  def self.inherited(subclass)
12
12
  super(subclass)
13
- T::Private::ClassUtils.replace_method(subclass.singleton_class, :inherited) do |s|
13
+ T::Private::ClassUtils.replace_method(subclass.singleton_class, :inherited, true) do |s|
14
14
  super(s)
15
15
  raise "#{self.name} is a subclass of T::Struct and cannot be subclassed"
16
16
  end
@@ -23,7 +23,7 @@ class T::ImmutableStruct < T::InexactStruct
23
23
  def self.inherited(subclass)
24
24
  super(subclass)
25
25
 
26
- T::Private::ClassUtils.replace_method(subclass.singleton_class, :inherited) do |s|
26
+ T::Private::ClassUtils.replace_method(subclass.singleton_class, :inherited, true) do |s|
27
27
  super(s)
28
28
  raise "#{self.name} is a subclass of T::ImmutableStruct and cannot be subclassed"
29
29
  end
@@ -4,6 +4,9 @@
4
4
  module T::Types
5
5
  # Validates that an object belongs to the specified class.
6
6
  class Simple < Base
7
+ NAME_METHOD = Module.instance_method(:name)
8
+ private_constant(:NAME_METHOD)
9
+
7
10
  attr_reader :raw_type
8
11
 
9
12
  def initialize(raw_type)
@@ -16,7 +19,7 @@ module T::Types
16
19
  #
17
20
  # `name` isn't normally a hot path for types, but it is used in initializing a T::Types::Union,
18
21
  # and so in `T.nilable`, and so in runtime constructions like `x = T.let(nil, T.nilable(Integer))`.
19
- @name ||= @raw_type.name.freeze
22
+ @name ||= (NAME_METHOD.bind(@raw_type).call || @raw_type.name).freeze
20
23
  end
21
24
 
22
25
  # overrides Base
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.10891
4
+ version: 0.5.10894
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-29 00:00:00.000000000 Z
11
+ date: 2023-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest