Message300892
1.
the following causes an assertion failure in Python/_warnings.c in
show_warning():
import warnings
class BadLoader:
def get_source(self, fullname):
class BadSource:
def splitlines(self):
return [42]
return BadSource()
del warnings._showwarnmsg
warnings.warn_explicit(message='foo', category=ArithmeticError, filename='bar',
lineno=1, module_globals={'__loader__': BadLoader(),
'__name__': 'foobar'})
in short, the assertion failure would happen in warnings.warn_explicit() in case
module_globals['__loader__'].get_source(module_globals['__name__']).splitlines()[lineno-1]
is not a str.
2.
the following raises a SystemError:
import warnings
class BadLoader:
def get_source(self, fullname):
class BadSource:
def splitlines(self):
return 42
return BadSource()
warnings.warn_explicit(message='foo', category=UserWarning, filename='bar',
lineno=42, module_globals={'__loader__': BadLoader(),
'__name__': 'foobar'})
in short, warnings.warn_explicit() raises the SystemError in case
module_globals['__loader__'].get_source(module_globals['__name__']).splitlines()
is not a list.
ISTM that adding a check in warnings_warn_explicit() (in Python/_warnings.c),
to check whether
module_globals['__loader__'].get_source(module_globals['__name__'])
is a str (after existing code found out that it isn't None) would prevent both
the assertion failure and the SystemError.
What do you think? Is it OK to permit get_source() to return only None or a str? |
|
Date |
User |
Action |
Args |
2017-08-26 18:48:22 | Oren Milman | set | recipients:
+ Oren Milman |
2017-08-26 18:48:22 | Oren Milman | set | messageid: <1503773302.07.0.816913451611.issue31285@psf.upfronthosting.co.za> |
2017-08-26 18:48:22 | Oren Milman | link | issue31285 messages |
2017-08-26 18:48:21 | Oren Milman | create | |
|