Author barry
Recipients barry
Date 2017-12-13.15:48:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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
>>> 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?
Date User Action Args
2017-12-13 15:48:41barrysetrecipients: + barry
2017-12-13 15:48:41barrysetmessageid: <>
2017-12-13 15:48:41barrylinkissue32305 messages
2017-12-13 15:48:41barrycreate