[New-bugs-announce] [issue15710] logging module crashes in Python 2.7.3 for handler.setLevel(long)

Tobin Baker report at bugs.python.org
Thu Aug 16 23:33:59 CEST 2012


New submission from Tobin Baker:

I'm using a 3rd-party library (ESAPI) which defines a log level as the literal -2**31. This worked fine until I upgraded to Python 2.7.3, which, unlike all previous versions of Python, coerces that literal to long rather than int. The following code in the logging module then throws a TypeError:

def _checkLevel(level):
    if isinstance(level, int):
        rv = level
    elif str(level) == level:
        if level not in _levelNames:
            raise ValueError("Unknown level: %r" % level)
        rv = _levelNames[level]
    else:
        raise TypeError("Level not an integer or a valid string: %r" % level)
    return rv

Although this is certainly an unusual use case, it seems that as just a matter of principle, the module should be using the check isinstance(level, (int, long)) rather than just isinstance(level, int).

Here's the relevant part of the traceback:

  File "/usr/lib/python2.7/logging/__init__.py", line 710, in setLevel
    self.level = _checkLevel(level)
  File "/usr/lib/python2.7/logging/__init__.py", line 190, in _checkLevel
    raise TypeError("Level not an integer or a valid string: %r" % level)
TypeError: Level not an integer or a valid string: -2147483648L

----------
components: Library (Lib)
messages: 168418
nosy: tobin.baker
priority: normal
severity: normal
status: open
title: logging module crashes in Python 2.7.3 for handler.setLevel(long)
type: crash
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15710>
_______________________________________


More information about the New-bugs-announce mailing list