[New-bugs-announce] [issue32305] Namespace packages have inconsistent __file__ and __spec__.origin
Barry A. Warsaw
report at bugs.python.org
Wed Dec 13 10:48:41 EST 2017
New submission from Barry A. Warsaw <barry at python.org>:
Along the lines of Issue32303 there's another inconsistency in namespace package metadata. Let's say I have a namespace package:
>>> importlib_resources.tests.data03.namespace
<module 'importlib_resources.tests.data03.namespace' (namespace)>
The package has no __file__ attribute, and it has a misleading __spec__.origin
>>> importlib_resources.tests.data03.namespace.__spec__.origin
'namespace'
>>> importlib_resources.tests.data03.namespace.__file__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'importlib_resources.tests.data03.namespace' has no attribute '__file__'
This is especially bad because the documentation for __spec__.origin implies a correlation to __file__, and says:
"Name of the place from which the module is loaded, e.g. “builtin” for built-in modules and the filename for modules loaded from source. Normally “origin” should be set, but it may be None (the default) which indicates it is unspecified."
I don't particularly like that its origin is "namespace". That's an odd special case that's unhelpful to test against (what if you import a non-namespace package from the directory "namespace"?)
What would break if __spec__.origin were (missing? or) None?
----------
messages: 308206
nosy: barry
priority: normal
severity: normal
status: open
title: Namespace packages have inconsistent __file__ and __spec__.origin
versions: Python 3.5, Python 3.6, Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32305>
_______________________________________
More information about the New-bugs-announce
mailing list