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