Title: Doc: Namespace Packages: Inconsistent documentation of __loader__ being None
Type: Stage: patch review
Components: Documentation Versions: Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: barry, brett.cannon, docs@python, eric.snow, maggyero, mdk, ncoghlan
Priority: normal Keywords: patch

Created on 2018-11-06 22:29 by mdk, last changed 2018-11-07 15:13 by maggyero.

Pull Requests
URL Status Linked Edit
PR 10376 open maggyero, 2018-11-07 14:43
PR 10016 open maggyero, 2018-11-07 14:47
Messages (2)
msg329392 - (view) Author: Julien Palard (mdk) * (Python committer) Date: 2018-11-06 22:29
The documentation states that a __loader__ of a namespace package should be None:

- [1] "For namespace packages this should be set to None."
- [2] "To indicate to the import machinery that the spec represents a namespace portion. the path entry finder sets “loader” on the spec to None".

But this looks wrong [3], looks like it has been changed in [4]/[5].

I think one should rely on __file__ being None on namespace packages (which make sense as they span over multiple directories) instead of __loader__ being None (a side effect of the import machinery ?).

msg329419 - (view) Author: Géry (maggyero) * Date: 2018-11-07 15:13
It looks like Barry Warsaw has not been fully updated the documentation after making the __spec__.loader attribute match with the __loader__ attribute, and the __spec__.file attribute match with the __file__ attribute for namespace packages.

Here is a pull request to update the library documentation of importlib (your first link [1]) with the current Barry's implementation:

Here is another pull request to update the reference documentation of the import system (your second link [2], but for a different paragraph, as I think the "To indicate to the import machinery that the spec represents a namespace portion the path entry finder sets “loader” on the spec to None" sentence is correct, since the `_bootstrap.ModuleSpec.loader` attribute of a namespace package remains `None` until the call to the `importlib._bootstrap._init_module_attrs` function):
Date User Action Args
2018-11-07 15:13:59maggyerosetnosy: + brett.cannon, ncoghlan, eric.snow, maggyero
messages: + msg329419
2018-11-07 14:47:06maggyerosetpull_requests: + pull_request9678
2018-11-07 14:43:39maggyerosetkeywords: + patch
stage: patch review
pull_requests: + pull_request9677
2018-11-06 23:41:53barrysetnosy: + barry
2018-11-06 22:29:09mdkcreate