Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IRB deprecation warning on tab-completion #37100

Merged
merged 1 commit into from Oct 7, 2019

Conversation

jonathanhefner
Copy link
Member

@jonathanhefner jonathanhefner commented Sep 1, 2019

IRB invokes #hash (via a call to Hash#include?) and #instance_methods on each object in ObjectSpace.each_object(Module) when performing tab-completion on chain of method calls. This patch prevents a deprecation warning from being printed when any of those objects are a ActiveSupport::Deprecation::DeprecatedConstantProxy.

Fixes #37097.

@jonathanhefner
Copy link
Member Author

The build errors appear to be unrelated. Something to do with failing to build eventmachine native extensions?

@@ -145,6 +145,10 @@ def inspect
target.inspect
end

# Don't give a deprecation warning on methods that IRB may invoke
# during tab-completion.
delegate :hash, :instance_methods, to: :target
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered future-proofing this with

delegate *BasicObject.public_instance_methods, to: :target

but that seems too heavy-handed. Would

delegate :hash, *BasicObject.public_instance_methods.grep(/methods/), to: :target

be better?

IRB invokes `#hash` (via a call to `Hash#include?`) and
`#instance_methods` on each object in `ObjectSpace.each_object(Module)`
when performing tab-completion on chain of method calls.  This patch
prevents a deprecation warning from being printed when any of those
objects are a `ActiveSupport::Deprecation::DeprecatedConstantProxy`.

Fixes rails#37097.
@kaspth kaspth merged commit cb823c1 into rails:master Oct 7, 2019
@kaspth
Copy link
Contributor

kaspth commented Oct 7, 2019

Thanks! Let's just keep it to this and see how well this fares in future Ruby versions. I'd rather not add the dynamic delegate just yet.

@swrobel
Copy link
Contributor

swrobel commented Nov 7, 2019

Will this be backported to 6-0-stable?

Edouard-chin added a commit to Edouard-chin/rails that referenced this pull request Nov 22, 2019
- Similar fix as rails#37100 which
  solved the issue only for ruby 2.6.

  Fix rails#37775
@joallard
Copy link

Thanks @kaspth, is there a way we can get this merged to 6-0-stable?

@rafaelfranca
Copy link
Member

Backported

rafaelfranca pushed a commit that referenced this pull request Jan 31, 2020
…warning

Fix IRB deprecation warning on tab-completion
@joallard
Copy link

Thanks so much!

kaspth pushed a commit that referenced this pull request Feb 7, 2020
@vixalien
Copy link

Can you explain to the non-intelligent people what to do? Do we update rails, downgrade it or update ruby

@jonathanhefner
Copy link
Member Author

@vixalien This fix will be included in Rails 6.0.3, though I'm not sure when that will be released. In the mean time, if you're feeling bold, you can point your Gemfile to the 6-0-stable branch of Rails:

gem "rails", github: "rails/rails", branch: "6-0-stable"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Rails 6] Pry and irb completion breaks on a minimal example with a rails-originated (spurious?) deprecation
6 participants