Bug #20900
closedNet.send(:remove_const, :HTTPSession) does not emit warnings
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>
Updated by yahonda (Yasuo Honda) about 1 month ago ยท Edited
I wish the :remove_const
should also emit the warnings so that at least WebMock users can be aware of this change.
Refer to:
https://github.com/bblimke/webmock/blob/9ff63ac7c845a75278e43236e0128e197f597462/lib/webmock/http_lib_adapters/net_http.rb#L18
https://github.com/bblimke/webmock/blob/9ff63ac7c845a75278e43236e0128e197f597462/lib/webmock/http_lib_adapters/net_http.rb#L25
Updated by hsbt (Hiroshi SHIBATA) about 1 month ago
I restore HTTPSession
at https://github.com/ruby/net-http/pull/191
Updated by nobu (Nobuyoshi Nakada) about 1 month ago
- Status changed from Open to Closed
Applied in changeset git|9c777f282f8482400d4b0c7993d520c18cb1b652.
[Bug #20900] Warn deprecated constant when removing
Updated by Earlopain (Earlopain _) about 1 month 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 1 month 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 1 month 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!