Project

General

Profile

Actions

Bug #20900

closed

Net.send(:remove_const, :HTTPSession) does not emit warnings

Added by yahonda (Yasuo Honda) about 11 hours ago. Updated about 4 hours ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x86_64-linux]
[ruby-core:119958]

Description

After https://github.com/ruby/net-http/pull/189 has been merged and cherry-picked to Ruby master branch,
Net.send(:remove_const, :HTTPSession) gets the NameError. This code should emit warnings against Ruby 3.3 or earlier versions of Ruby but actually it does not.

$ ruby -v
ruby 3.4.0dev (2024-11-18T15:04:50Z :detached: 4a7ac694e5) +PRISM [x86_64-linux]
$ irb -w
... snip ...
irb(main):001> require 'net/http'
=> true
irb(main):002> Net.send(:remove_const, :HTTPSession)
(irb):2:in 'Module#remove_const': constant Net::HTTPSession not defined (NameError)
	from (irb):2:in '<main>'
	from <internal:kernel>:168:in 'Kernel#loop'
	from /home/yahonda/.rbenv/versions/trunk/lib/ruby/gems/3.4.0+1/gems/irb-1.14.1/exe/irb:9:in '<top (required)>'
	from /home/yahonda/.rbenv/versions/trunk/bin/irb:25:in 'Kernel#load'
	from /home/yahonda/.rbenv/versions/trunk/bin/irb:25:in '<main>'
irb(main):003>

Steps to reproduce

Here are the steps to see if the warnings are emitted against Ruby 3.3.

$ ruby -v
ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x86_64-linux]
$ irb -w

require 'net/http'
Net::HTTPSession
Net.send(:remove_const, :HTTPSession)

Expected behavior

Both of Net::HTTPSession and Net.send(:remove_const, :HTTPSession) should emit the warning: constant Net::HTTPSession is deprecated .

Actual behavior

Only Net::HTTPSession emits the warnings. Net.send(:remove_const, :HTTPSession) does not emit any warnings.

$ irb -w
irb(main):001> require 'net/http'
irb(main):002>
=> true
irb(main):003> Net::HTTPSession
(irb):3: warning: constant Net::HTTPSession is deprecated
=> Net::HTTP
irb(main):004> Net.send(:remove_const, :HTTPSession)
=> Net::HTTP
irb(main):005>
Actions #3

Updated by nobu (Nobuyoshi Nakada) about 9 hours ago

  • Status changed from Open to Closed

Applied in changeset git|9c777f282f8482400d4b0c7993d520c18cb1b652.


[Bug #20900] Warn deprecated constant when removing

Updated by Earlopain (Earlopain _) about 5 hours ago

I think warning on removal is a good thing. It makes compatibility code in webmock a bit more involved but that's totally fine.

hsbt (Hiroshi SHIBATA) wrote in #note-2:

I restore HTTPSession at https://github.com/ruby/net-http/pull/191

You added it as Net::HTTP::HTTPSession, it used to be just Net::HTTPSession.

Updated by hsbt (Hiroshi SHIBATA) about 4 hours ago

You added it as Net::HTTP::HTTPSession, it used to be just Net::HTTPSession.

I fixed that at https://github.com/ruby/ruby/commit/716ea630dbd6cea62049a7a438d7d4f4f84d4aae

Updated by Earlopain (Earlopain _) about 4 hours ago

hsbt (Hiroshi SHIBATA) wrote in #note-5:

You added it as Net::HTTP::HTTPSession, it used to be just Net::HTTPSession.

I fixed that at https://github.com/ruby/ruby/commit/716ea630dbd6cea62049a7a438d7d4f4f84d4aae

Thanks!

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0