Backwards Incompatibility in logging module in 3.4?
Hi there, I just started testing a project of mine on Python 3.4.0b1. I ran into a change that broke compatibility with the logging module in 3.3. The basic test is: $ py34/bin/python -c 'import logging; print(logging.getLevelName("debug".upper()))' Level DEBUG $ py33/bin/python -c 'import logging; print(logging.getLevelName("debug".upper()))' 10 I quickly stumbled upon this webpage: http://aazza.github.io/2014/05/31/testing-on-multiple-versions-of-Python/ Which led me to this ticket regarding the change: http://bugs.python.org/issue18046 Is this a bug or an intentional break? If it's the latter, shouldn't this at least be mentioned in the "What's new in Python 3.4" document? If it's the former, should I file a bug? Thanks, Don
On 13 Jun 2014 08:59, "Don Spaulding"
Hi there,
I just started testing a project of mine on Python 3.4.0b1. I ran into a
change that broke compatibility with the logging module in 3.3.
The basic test is:
$ py34/bin/python -c 'import logging;
print(logging.getLevelName("debug".upper()))'
Level DEBUG
$ py33/bin/python -c 'import logging;
print(logging.getLevelName("debug".upper()))'
10
I quickly stumbled upon this webpage:
http://aazza.github.io/2014/05/31/testing-on-multiple-versions-of-Python/
Which led me to this ticket regarding the change:
http://bugs.python.org/issue18046
Is this a bug or an intentional break? If it's the latter, shouldn't
this at least be mentioned in the "What's new in Python 3.4" document? If it's the former, should I file a bug? Yes, it sounds like a bug to me - there's no indication of an intent to change behaviour with that cleanup patch. Cheers, Nick.
Thanks, Don
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe:
https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com
Hi,
2014-06-13 0:38 GMT+02:00 Don Spaulding
Is this a bug or an intentional break? If it's the latter, shouldn't this at least be mentioned in the "What's new in Python 3.4" document?
IMO the change is intentional. The previous behaviour was not really expected. Python 3.3 documentation is explicit: the result is a string and the input paramter is an integer. logging.getLevelName("DEBUG") was more an implementation https://docs.python.org/3.3/library/logging.html#logging.getLevelName "Returns the textual representation of logging level lvl. If the level is one of the predefined levels CRITICAL, ERROR, WARNING, INFO or DEBUG then you get the corresponding string. If you have associated levels with names using addLevelName() then the name you have associated with lvl is returned. If a numeric value corresponding to one of the defined levels is passed in, the corresponding string representation is returned. Otherwise, the string ‘Level %s’ % lvl is returned." If your code uses something like logger.setLevel(logging.getLevelName("DEBUG")), use directly logger.setLevel("DEBUG"). This issue was fixed in OpenStack with this change: https://review.openstack.org/#/c/94028/6/openstack/common/log.py,cm https://review.openstack.org/#/c/94028/6 Victor
On Thu, Jun 12, 2014 at 6:45 PM, Victor Stinner
Hi,
Is this a bug or an intentional break? If it's the latter, shouldn't
2014-06-13 0:38 GMT+02:00 Don Spaulding
: this at least be mentioned in the "What's new in Python 3.4" document?
IMO the change is intentional. The previous behaviour was not really expected.
I agree that the change seems intentional. However, as Nick mentioned, the ticket doesn't really discuss the repercussions of changing the output of the function. As far as I can tell, this function has returned an int when given a string since it was introduced in Python 2.3. I think it's reasonable to call a function's behavior "expected" after 11 years in the wild.
Python 3.3 documentation is explicit: the result is a string and the input paramter is an integer. logging.getLevelName("DEBUG") was more an implementation
https://docs.python.org/3.3/library/logging.html#logging.getLevelName "Returns the textual representation of logging level lvl. If the level is one of the predefined levels CRITICAL, ERROR, WARNING, INFO or DEBUG then you get the corresponding string. If you have associated levels with names using addLevelName() then the name you have associated with lvl is returned. If a numeric value corresponding to one of the defined levels is passed in, the corresponding string representation is returned. Otherwise, the string ‘Level %s’ % lvl is returned."
If your code uses something like logger.setLevel(logging.getLevelName("DEBUG")), use directly logger.setLevel("DEBUG").
This issue was fixed in OpenStack with this change: https://review.openstack.org/#/c/94028/6/openstack/common/log.py,cm https://review.openstack.org/#/c/94028/6
Victor
I appreciate the pointer to the OpenStack fix. I've actually already worked around the issue in my project (although without much elegance, I'll readily admit). I opened up an issue on the tracker for this: http://bugs.python.org/issue21752 I apologize if that was out of turn.
On 14 Jun 2014 06:18, "Don Spaulding"
I opened up an issue on the tracker for this:
http://bugs.python.org/issue21752
I apologize if that was out of turn.
At the very least, there should be a note in the "porting to Python 3.4" section of the What's New and a versionchanged note on the API docs, so a docs bug report is appropriate to add those. Cheers, Nick.
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe:
https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com
participants (3)
-
Don Spaulding
-
Nick Coghlan
-
Victor Stinner