importlib.util._find_spec_from_path('__main__') fails
Open
Nobody has claimed this yet.
stdlib
topic-importlib
type-bug
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
Bug report
Module pyclbr cannot browse a file named __main__ because it cannot get the spec.
>>> from importlib import util
>>> util._find_spec_from_path('__init__')
ModuleSpec(name='__init__', loader=<_frozen_importlib_external.SourceFileLoader object at 0x000001C6C2462DB0>, origin='C:\\Programs\\Python313\\Lib\\idlelib\\__init__.py')
>>> util._find_spec_from_path('__main__')
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
util._find_spec_from_path('__main__')
File "<frozen importlib.util>", line 67, in _find_spec_from_path
ValueError: __main__.__spec__ is None
This is 3.13.0a5 but same in prior versions.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with importlib.util._find_spec_from_path('main') and trace how pyclbr requests a spec for a file named main. Inspect the importlib.util path and the pyclbr behavior described in the report. Done means pyclbr can browse a file named main without the ValueError shown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100