[New-bugs-announce] [issue43299] pyclbr.readmodule_ex traversing "import __main__": dies with ValueError: __main__.__spec__ is None / is not set

Robert report at bugs.python.org
Mon Feb 22 12:48:25 EST 2021


New submission from Robert <kxroberto at gmail.com>:

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

----------
components: Library (Lib)
messages: 387520
nosy: kxrob
priority: normal
severity: normal
status: open
title: pyclbr.readmodule_ex traversing "import __main__": dies with ValueError: __main__.__spec__ is None / is not set
type: crash
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43299>
_______________________________________


More information about the New-bugs-announce mailing list