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.

----------
assignee: brett.cannon
messages: 181279
nosy: brett.cannon
priority: normal
severity: normal
stage: test needed
status: open
title: __loader__ = None should be fine
type: behavior
versions: Python 3.4

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue17115>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to