Title: pyclbr.readmodule_ex traversing "import __main__": dies with ValueError: __main__.__spec__ is None / is not set
Type: crash Stage: patch review
Components: Library (Lib) Versions: Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: kxrob
Priority: normal Keywords: patch

Created on 2021-02-22 17:48 by kxrob, last changed 2021-02-22 18:46 by kxrob.

Pull Requests
URL Status Linked Edit
PR 24623 open kxrob, 2021-02-22 18:46
Messages (1)
msg387520 - (view) Author: Robert (kxrob) * Date: 2021-02-22 17:48
When pyclbr.readmodule_ex() is traversing "import __main__" or another 
module without __spec__, it dies completely 
with "ValueError: __main__.__spec__ is None / is not set".

=> It should at least continue with the (big) rest 
as the comment in _ModuleBrowser.visit_Import() says:
            # If we can't find or parse the imported module,
            # too bad -- don't die here.

And optionally fall back to using __file__ when present?

Traceback (most recent call last):
  File "C:\Python310\Lib\site-packages\pythonwin\pywin\framework\editor\", line 128, in OnActivateView
  File "C:\Python310\Lib\site-packages\pythonwin\pywin\framework\editor\", line 181, in CheckRefreshList
  File "C:\Python310\Lib\site-packages\pythonwin\pywin\framework\editor\", line 173, in CheckMadeList
    self.rootitem = root = self._MakeRoot()
  File "C:\Python310\Lib\site-packages\pythonwin\pywin\framework\editor\", line 153, in _MakeRoot
    data = reader(mod, path and [path])
  File "C:\Python310\lib\", line 120, in readmodule_ex
    return _readmodule(module, path or [])
  File "C:\Python310\lib\", line 159, in _readmodule
    return _readmodule(submodule, parent['__path__'], package)
  File "C:\Python310\lib\", line 184, in _readmodule
    return _create_tree(fullmodule, path, fname, source, tree, inpackage)
  File "C:\Python310\lib\", line 272, in _create_tree
  File "C:\Python310\lib\", line 410, in visit
    return visitor(node)
  File "C:\Python310\lib\", line 418, in generic_visit
  File "C:\Python310\lib\", line 410, in visit
    return visitor(node)
  File "C:\Python310\lib\", line 243, in visit_Import
    _readmodule(, [])
  File "C:\Python310\lib\", line 167, in _readmodule
    spec = importlib.util._find_spec_from_path(fullmodule, search_path)
  File "C:\Python310\lib\importlib\", line 69, in _find_spec_from_path
    raise ValueError('{}.__spec__ is None'.format(name))
ValueError: __main__.__spec__ is None
Date User Action Args
2021-02-22 18:46:38kxrobsetkeywords: + patch
stage: patch review
pull_requests: + pull_request23407
2021-02-22 17:48:25kxrobcreate