New submission from Serhiy Storchaka:

Seems there is a bug in the implementation of the IMPORT_NAME opcode in ceval.c.

If the level argument is -1, it is not passed to __import__ (should never 
happen, but looks correct). If it is an integer != -1 in C long range, it is 
passed to __import__ (this is correct). But if it is not integer (e.g. None) or 
can't be converted to C long, an exception is set and __import__ is called with 
level and not cleared error (this is wrong).

In correct bytecode the level argument can be either integer or None. Default 
__import__ accepts only integers as the level argument and checks the range. 
Proposed patch makes the code always passing the level argument to __import__ 
unless it is None.

----------
components: Interpreter Core
files: import_name_level.patch
keywords: patch
messages: 268849
nosy: brett.cannon, eric.snow, ncoghlan, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Bug in IMPORT_NAME
type: behavior
versions: Python 2.7, Python 3.5, Python 3.6
Added file: http://bugs.python.org/file43470/import_name_level.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27352>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to