Skip to content

Commit

Permalink
🔇 Add silence_thread_safety_deprecation_warnings
Browse files Browse the repository at this point in the history
This is provided as a temporary workaround, until dependant projects can
update their usage.

A future release will remove this backwards compatibility, but no sooner
than one year after the release that contains this deprecation warning.
  • Loading branch information
nevans committed May 19, 2024
1 parent 1136bd8 commit 4c1f98e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,18 @@ class << self
alias default_imap_port default_port
alias default_imaps_port default_tls_port
alias default_ssl_port default_tls_port

# Set to true to silence deprecation warnings, e.g. from #responses.
# Defaults to false.
#
# These warnings are concerning thread-safety issues, so it is recommended
# to update other code and leave this value. Deprecated usage will
# become errors regardless of this setting, so use this only temporarily.
attr_accessor :silence_thread_safety_deprecation_warnings
end

self.silence_thread_safety_deprecation_warnings = false

# Returns the initial greeting the server, an UntaggedResponse.
attr_reader :greeting

Expand Down Expand Up @@ -2501,7 +2511,9 @@ def responses(type = nil)
elsif type
raise ArgumentError, "Pass a block or use #clear_responses"
else
warn("DEPRECATED: pass a block or use #clear_responses", uplevel: 1)
unless IMAP.silence_thread_safety_deprecation_warnings
warn("DEPRECATED: pass a block or use #clear_responses", uplevel: 1)
end
@responses
end
end
Expand Down
11 changes: 11 additions & 0 deletions test/net/imap/test_imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,8 @@ def test_enable

def test_responses
with_fake_server do |server, imap|
original_silence = Net::IMAP.silence_thread_safety_deprecation_warnings
Net::IMAP.silence_thread_safety_deprecation_warnings = false
# responses available before SELECT/EXAMINE
assert_equal(%w[IMAP4REV1 NAMESPACE MOVE IDLE UTF8=ACCEPT],
imap.responses("CAPABILITY", &:last))
Expand All @@ -1108,6 +1110,15 @@ def test_responses
assert_equal(%i[Answered Flagged Deleted Seen Draft],
imap.responses["FLAGS"]&.last)
end
Net::IMAP.silence_thread_safety_deprecation_warnings = true
# TODO: assert_no_warn?
stderr = EnvUtil.verbose_warning {
assert_equal(%i[Answered Flagged Deleted Seen Draft],
imap.responses["FLAGS"]&.last)
}
assert_empty stderr
ensure
Net::IMAP.silence_thread_safety_deprecation_warnings = original_silence
end
end

Expand Down

0 comments on commit 4c1f98e

Please sign in to comment.