New submission from Oren Milman:
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?
----------
components: Interpreter Core
messages: 300892
nosy: Oren Milman
priority: normal
severity: normal
status: open
title: a SystemError and an assertion failure in warnings.warn_explicit()
type: crash
versions: Python 3.7
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue31285>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com