-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
Remove deprecated logging.Logger.warn() method in Python 3.13 #105376
Comments
this likely won't affect us for a while, but might as well clean it up python/cpython#105376
this likely won't affect us for a while, but might as well clean it up python/cpython#105376
Python 3.13 removed it. See python/cpython#105376
I would like to speak up for reversing this change. A lot of people, especially non-professional programmers, have written a lot of code with If this really is going to be removed, I would recommend at least one Python release where using EDIT: I didn't notice until after I posted that the SyntaxWarning for invalid escape sequences was also done by @vstinner ! |
Whereas invalid escape sequences might reasonably be considered syntax warnings, I'm not sure that applies to methods that were deprecated long ago. In any case, it's easy enough for users to fix their broken code, in the (presumably) very rare instances where they didn't see the deprecation warning because they upgraded to the very latest Python version from a pre- 3.3 version. Can you explain why you think a |
These can be found with the Ruff linter: https://docs.astral.sh/ruff/rules/#flake8-logging-format-g For example: ruff check --isolated --select G010 . And auto-fixed: ruff check --isolated --select G010 . --fix And found with pylint: https://pylint.readthedocs.io/en/stable/user_guide/messages/warning/deprecated-method.html pylint --disable=all --enable=W4902 . And a Flake8 plugin: https://pypi.org/project/flake8-logging-format/ |
@vsajip My preferred solution is to keep the If that isn't possible, I recommended the SyntaxWarning approach because I thought that it is visible by default, whereas DeprecationWarning is invisible by default. But based on some quick testing, that seems like it's not actually the case, at least universally. I was trying to replicate this kind of behavior, where the warning about the deprecated behavior became more visible in 3.12:
|
I've no idea what you mean - ~> python3
Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:18:16) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.warn('foo')
<stdin>:1: DeprecationWarning: The 'warn' function is deprecated, use 'warning' instead
WARNING:root:foo
>>> logging.getLogger().warn('bar')
<stdin>:1: DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead
WARNING:root:bar
>>> |
Right, I have realized I was wrong about that. I don't know much about how warnings work, honestly. My belief was based off of this comment
which is about a SyntaxError, not a SyntaxWarning. I was reading it wrong. I still think the |
I removed Logger.warn() because it was deprecated since Python 3.3. Sadly, DeprecationWarning is silent by default: you have to run Calling Either we decide that |
Since Python 3.7, DeprecationWarning are shown in the main module: https://peps.python.org/pep-0565/ It includes the REPL. But DeprecationWarning is still hidden by default if the warning is emitted from another module. |
TIL! I'm OK with the current state. |
I don't see a problem with keeping (adding back) the |
I created PR gh-122775 to restore the deprecated logging warn() method. |
I vote to keep it. This is hardly a maintenance burden - if we were to drop the deprecation warning then it's no maintenance burden at all. "warn()", a verb, is a better method name anyway. I would normally assume "logging.warning" is a constant or type. |
In this case, the methods just echo the names of the levels they log at - they are just conveniences for the verb "log at ". |
The novelty of |
This is not true. The wrapper was an additional concern in #28287. In fact, it absorbed a substantial part of the total effort. Remember the Zen of Python:
I'm in favor of removing the long-deprecated method. |
If we dropped the warning (which was the part of my message you clipped out), it would be an alias of |
…22775) This reverts commit dcc028d and commit 6c54e5d. Keep the deprecated logging warn() method in Python 3.13. (cherry picked from commit d323997) Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Gregory P. Smith <greg@krypto.org> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
#122856) gh-105376: Restore deprecated logging warn() method (GH-122775) This reverts commit dcc028d and commit 6c54e5d. Keep the deprecated logging warn() method in Python 3.13. (cherry picked from commit d323997) Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Gregory P. Smith <greg@krypto.org> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
I added again the warn() method. |
The logging.Logger.warn() method was deprecated in Python 3.3 by issue #57444 and commit 04d5bc0. This method is not documented and emits a DeprecationWarning since Python 3.3.
#57444 (comment):
I propose to remove this logging.Logger.warn() method in Python 3.13.
Linked PRs
The text was updated successfully, but these errors were encountered: