[New-bugs-announce] [issue17115] __loader__ = None should be fine
report at bugs.python.org
Sun Feb 3 17:47:26 CET 2013
New submission from Brett Cannon:
There is no reason __loader__ can't be set to None like __package__. That means having xml.parsers.expat.(model|errors) set the attribute to None by default (and thus removing the exemption for those modules from test_importlib.test_api.StartupTests), updating the decorators in importlib.util to set __loader__ when it is None, and make importlib.find_loader() treat None the same as if the attribute isn't set (e.g. unifying the raising of ValueError in both cases).
This will bring __loader__ back in alignment with __package__.
In all honesty I would like to tweak imp.new_module()/PyModule_Create() to set both __package__ and __loader__ to None by default, but I don't know how much code out there relies on the absence of these attributes and not on them being set to None (although fixing all of that code is simply transitioning from hasattr(module, '__loader__') to getattr(module, '__loader__', None)). Luckily PEP 302 was updated a couple versions back to state the loaders **must** set these attributes, so hopefully as time goes on this will be less of a worry.
stage: test needed
title: __loader__ = None should be fine
versions: Python 3.4
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce