Brett Cannon br...@python.org added the comment:
Detecting if you are in a package is as simple as ``'.' in __name__ or
hasattr(mod, '__path__')`` or alternatively for the last guard, ``__name__ ==
__package__``.
As for the failure, I will have a look.
--
Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com:
--
nosy: +Arfrever
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14592
___
Roundup Robot devn...@psf.upfronthosting.co.za added the comment:
New changeset 68f9ad6a3b13 by Brett Cannon in branch 'default':
Issue #14592: A relative import will raise a KeyError if __package__
http://hg.python.org/cpython/rev/68f9ad6a3b13
--
nosy: +python-dev
Brett Cannon br...@python.org added the comment:
SystemError fixed (stemming from a misunderstanding of what
PyDict_GetItemWithError() did).
--
assignee: - brett.cannon
resolution: - fixed
stage: - committed/rejected
status: open - closed
___
New submission from Stefan Behnel sco...@users.sourceforge.net:
Up to the early Py3.3 developer versions, calling __import__() with a level of
-1 worked as in Python 2, i.e. it tried a relative import first and then a
global import.
This no longer seems to be available after the importlib
Changes by R. David Murray rdmur...@bitdance.com:
--
nosy: +brett.cannon
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14592
___
___
Benjamin Peterson benja...@python.org added the comment:
Relative imports are no longer supported in python 3, so this makes sense.
--
nosy: +benjamin.peterson
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14592
Benjamin Peterson benja...@python.org added the comment:
By relative I meant sibling.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14592
___
Brett Cannon br...@python.org added the comment:
What Benjamin said. PEP 328 should have done away with relative imports, but
somehow the __import__() function itself was not updated even though its docs
were changed to say that index defaulted to 0.
So this isn't actually a regressions
Brett Cannon br...@python.org added the comment:
I should also mention that the support for -1 indexing in Python 3 was weird
because support was partially removed, but some 'if' checks only did `` 1``
and so negative indices didn't trigger an error.
--
Changes by Eric Snow ericsnowcurren...@gmail.com:
--
nosy: +eric.snow
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14592
___
___
Python-bugs-list
Stefan Behnel sco...@users.sourceforge.net added the comment:
It turns out that it wasn't all that hard to work around. Calling __import__
twice seems to do the trick. It's more overhead, but if people want speed, they
can just be explicit about what kind of import they actually mean.
So I
Brett Cannon br...@python.org added the comment:
Yeah, the fix is dead-simple, import with level=1 and if that fails import with
level=0.
I plan to cover this specific issue in the What's New for Python 3.3.
--
___
Python tracker
Stefan Behnel sco...@users.sourceforge.net added the comment:
Yeah, the fix is dead-simple, import with level=1 and if that fails import
with level=0.
With one caveat: relative imports don't work outside of packages, so the
importing code has to know when it's in a package or not. Otherwise,
Stefan Behnel sco...@users.sourceforge.net added the comment:
Hmm, interesting - it stripped the command from my e-mail. I was doing this:
__import__(sys, level=1)
Traceback (most recent call last):
File stdin, line 1, in module
SystemError: error return without exception set
--
15 matches
Mail list logo