[issue35806] typing module adds objects to sys.modules that don't look like modules

Ronald Oussoren report at bugs.python.org
Sun Jan 27 16:49:49 EST 2019


Ronald Oussoren <ronaldoussoren at mac.com> added the comment:

Note that I will have to special case namespaces like typing.re anyway in my code, being a namespace that does not correspond to a "real" module whose code I can analyse.

#35791 was mostly about 3th-party code like apipkg that are "real" modules, but for some reason effectively erase there __spec__ attribute. In those cases find_spec could return valid value.

As I mentioned in the other issue I have a simple workaround for this, and that's something I'll have to keep around for a while anyway. 

I'm not convinced at this point that anything needs to be changed, as long as the documentation is clear on the requirement that modules should have a __spec__ attribute (which makes it easier to convince 3th-party authors to update their code). 

Special cases like typing.re will always be special, and adding __spec__ to them won't change a lot there (the only vaguely useful attribute in the ModuleSpec for typing.re would be "name" and "parent") and IMHO would be needless code churn.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35806>
_______________________________________


More information about the Python-bugs-list mailing list