New submission from mental <m3n...@yahoo.com>:

Hi folks! (apologies in advance if any of the code blocks come out irregular, 
this is my first issue)


I was just exploring the `Lib` modules out of curiosity and I discovered 
`pyclbr` a peculiar artifact from the older days of the Python standard library.

I noticed the module could be run directly and after attempting to run it 
withan invalid source target `python -m pyclbr somenonexistentfile` it raised 
```
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3.7/pyclbr.py", line 405, in <module>
    _main()
  File "/usr/lib/python3.7/pyclbr.py", line 380, in _main
    tree = readmodule_ex(mod, path)
  File "/usr/lib/python3.7/pyclbr.py", line 116, in readmodule_ex
    return _readmodule(module, path or [])
  File "/usr/lib/python3.7/pyclbr.py", line 169, in _readmodule
    if spec.submodule_search_locations is not None:
AttributeError: 'NoneType' object has no attribute 
'submodule_search_locations'```

I was running 3.7.2, although I assume this affects future versions and 
possibly some older versions. (I suspect the bug originates from importlib 
silently breaking backwards compatability)

I thought it strange for a script to exit so loudly so after reading through 
the source I believe the intended behavior meant for an invalid target is to 
raise an `ImportError` although I admit I'm not convinced this is still the 
best way to exit from erroneous input (or even if the module is still relevant 
in todays code?)

I believe this is a bug (but I would very much appreciate a second opinion) and 
I've identified it as a low priority easy fix, In which case I'd be more than 
happy to submit a fix :)

----------
messages: 337966
nosy: mental
priority: normal
severity: normal
status: open
title: Lib/pyclbr.py crashes when the package spec cannot be determined by 
importlib
type: crash
versions: Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36298>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to