This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author FFY00
Recipients FFY00, Greg Whiteley, barry, cajetan.rodrigues, dkasak, eric.smith, eric.snow
Date 2021-10-23.21:13:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1635023592.31.0.985479339714.issue40350@roundup.psfhosted.org>
In-reply-to
Content
I opened up a new PR that should fix this properly. The root issue was that PathFinder was not setting the loader attribute for namespace packages in the spec, which it should. After fixing that, _find_module just needed to be updated to deal with NamespaceLoader.

```
$ tree namespace
namespace/
└── a.py

0 directories, 1 file
$ cat test-bpo-40350.py
import namespace.a
```

```
$ ./python
Python 3.11.0a1+ (heads/main:9e05da6224, Oct 23 2021, 20:36:14) [GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import modulefinder
>>> modulefinder.ModuleFinder('test-bpo-40350.py')
<modulefinder.ModuleFinder object at 0x7f66f7647480>
>>> f = modulefinder.ModuleFinder('test-bpo-40350.py')
>>> f.
KeyboardInterrupt
>>> m = modulefinder.ModuleFinder()
>>> f = modulefinder.ModuleFinder()
>>> f.run_script('test-bpo-40350.py')
>>> f.modules.items()
dict_items([('__main__', Module('__main__', 'test-bpo-40350.py')), ('namespace', Module('namespace', _NamespacePath(['/home/anubis/git/cpython/namespace'])))])
```

Previously:
```
$ python
Python 3.9.7 (default, Oct 10 2021, 15:13:22)
[GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import modulefinder
>>> f = modulefinder.ModuleFinder()
>>> f.run_script('test-bpo-40350.py')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.9/modulefinder.py", line 161, in run_script
    self.load_module('__main__', fp, pathname, stuff)
  File "/usr/lib/python3.9/modulefinder.py", line 357, in load_module
    self.scan_code(co, m)
  File "/usr/lib/python3.9/modulefinder.py", line 430, in scan_code
    self._safe_import_hook(name, m, fromlist, level=0)
  File "/usr/lib/python3.9/modulefinder.py", line 375, in _safe_import_hook
    self.import_hook(name, caller, level=level)
  File "/usr/lib/python3.9/modulefinder.py", line 173, in import_hook
    q, tail = self.find_head_package(parent, name)
  File "/usr/lib/python3.9/modulefinder.py", line 229, in find_head_package
    q = self.import_module(head, qname, parent)
  File "/usr/lib/python3.9/modulefinder.py", line 316, in import_module
    fp, pathname, stuff = self.find_module(partname,
  File "/usr/lib/python3.9/modulefinder.py", line 508, in find_module
    return _find_module(name, path)
  File "/usr/lib/python3.9/modulefinder.py", line 77, in _find_module
    if spec.loader.is_package(name):
AttributeError: 'NoneType' object has no attribute 'is_package'
```
History
Date User Action Args
2021-10-23 21:13:12FFY00setrecipients: + FFY00, barry, eric.smith, dkasak, eric.snow, cajetan.rodrigues, Greg Whiteley
2021-10-23 21:13:12FFY00setmessageid: <1635023592.31.0.985479339714.issue40350@roundup.psfhosted.org>
2021-10-23 21:13:12FFY00linkissue40350 messages
2021-10-23 21:13:12FFY00create