[Python-Dev] Backwards Incompatibility in logging module in 3.4? (original) (raw)

Don Spaulding donspauldingii at gmail.com
Fri Jun 13 21:11:31 CEST 2014


On Thu, Jun 12, 2014 at 6:45 PM, Victor Stinner <victor.stinner at gmail.com> wrote:

Hi,

2014-06-13 0:38 GMT+02:00 Don Spaulding <donspauldingii at gmail.com>: > 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.

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. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20140613/6500e721/attachment.html>



More information about the Python-Dev mailing list