Author: Ronan Lamy <ronan.l...@gmail.com> Branch: py3.5 Changeset: r88458:3dc6e1434de4 Date: 2016-11-18 01:50 +0000 http://bitbucket.org/pypy/pypy/changeset/3dc6e1434de4/
Log: Implement http://bugs.python.org/issue17636 diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py --- a/pypy/interpreter/pyopcode.py +++ b/pypy/interpreter/pyopcode.py @@ -1019,14 +1019,25 @@ def IMPORT_FROM(self, nameindex, next_instr): w_name = self.getname_w(nameindex) w_module = self.peekvalue() + self.pushvalue(self.import_from(w_module, w_name)) + + def import_from(self, w_module, w_name): + space = self.space try: - w_obj = self.space.getattr(w_module, w_name) + return space.getattr(w_module, w_name) except OperationError as e: - if not e.match(self.space, self.space.w_AttributeError): + if not e.match(space, space.w_AttributeError): raise - raise oefmt(self.space.w_ImportError, - "cannot import name %R", w_name) - self.pushvalue(w_obj) + try: + w_pkgname = space.getattr( + w_module, space.newunicode(u'__name__')) + w_fullname = space.newunicode(u'%s.%s' % + (space.unicode_w(w_pkgname), space.unicode_w(w_name))) + return space.getitem(space.sys.get('modules'), w_fullname) + except OperationError: + raise oefmt( + space.w_ImportError, "cannot import name %R", w_name) + def YIELD_VALUE(self, oparg, next_instr): raise Yield diff --git a/pypy/module/imp/test/test_import.py b/pypy/module/imp/test/test_import.py --- a/pypy/module/imp/test/test_import.py +++ b/pypy/module/imp/test/test_import.py @@ -128,6 +128,10 @@ a = '', b = '', c = '') + setuppkg('circular', + circ1="from . import circ2", + circ2="from . import circ1") + p = setuppkg("encoded", # actually a line 2, setuppkg() sets up a line1 line2 = "# encoding: iso-8859-1\n", @@ -179,7 +183,7 @@ class AppTestImport(BaseFSEncodeTest): spaceconfig = { - "usemodules": ['_md5', 'time', 'struct', '_pypyjson'], + "usemodules": ['_md5', 'time', 'struct'], } def setup_class(cls): @@ -510,6 +514,9 @@ check_absolute() raises(TypeError, check_relative) + def test_relative_circular(self): + import circular.circ1 # doesn't fail + def test_import_function(self): # More tests for __import__ import sys _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit