Repository navigation
repr() of ImportError misses keyword arguments name and path #74185
Description
Activity
The repr of standard exceptions usually looks as exception constructor used for creating that exception. But the repr of ImportError misses keyword arguments name and path.
>>> ImportError('test', name='somename', path='somepath') ImportError('test',)
Proposed patch make the repr of ImportError containing keyword arguments.
>>> ImportError('test', name='somename', path='somepath') ImportError('test', name='somename', path='somepath')
I don't know how to classify this issue and whether the patch should be backported.
- added3.7 (EOL)end of lifeend of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on Apr 5, 2017 I consider it an enhancement, especially if someone was sloppy with their tests and explicitly checks the repr of ImportError.
- addedtype-featureA feature request or enhancementA feature request or enhancement
on Apr 6, 2017 The patch also changes the repr of BaseException with a single argument. It no longer contains a trailing comma.
Including 'path' may make the repr less readable in some cases. +1 for 'name', though.
I think the issue steems from the more general bpo-27015 for which a PR is ready that fixes the repr not only for ImportError but all other BaseException subclasses that override __init__.
- added3.12only security fixesonly security fixesand removed3.7 (EOL)end of lifeend of life
on Oct 29, 2022 The PRs need to be updated. Marking as easy.
@iritkatriel PR updated by @arhadthedev I think PR is ready to merge.
- added3.13only security fixesonly security fixesand removed3.12only security fixesonly security fixes
on Jan 5, 2024 trying to revive this issue by building on the previous PRs #136770
- added a commit that references this issue
on Aug 14, 2025 Implemented by c87b66b.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs