Skip to content

repr() of ImportError misses keyword arguments name and path #74185

Description

@serhiy-storchaka
BPO 29999
Nosy @brettcannon, @ncoghlan, @ericsnowcurrently, @berkerpeksag, @serhiy-storchaka, @remilapeyre
PRs
  • gh-74185: repr() of ImportError now contains attributes name and path. #1011
  • bpo-27015: Save kwargs given to exceptions constructor #11580
  • 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:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = None
    created_at = <Date 2017-04-05.22:29:11.771>
    labels = ['interpreter-core', 'type-feature', '3.7']
    title = 'repr() of ImportError misses keyword arguments name and path'
    updated_at = <Date 2019-01-30.16:00:33.577>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2019-01-30.16:00:33.577>
    actor = 'remi.lapeyre'
    assignee = 'serhiy.storchaka'
    closed = False
    closed_date = None
    closer = None
    components = ['Interpreter Core']
    creation = <Date 2017-04-05.22:29:11.771>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 29999
    keywords = ['patch']
    message_count = 5.0
    messages = ['291200', '291241', '291633', '292205', '334569']
    nosy_count = 6.0
    nosy_names = ['brett.cannon', 'ncoghlan', 'eric.snow', 'berker.peksag', 'serhiy.storchaka', 'remi.lapeyre']
    pr_nums = ['1011', '11580']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue29999'
    versions = ['Python 3.7']

    Linked PRs

    Activity

    serhiy-storchaka commented on Apr 5, 2017

    @serhiy-storchaka
    MemberAuthor

    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.

    brettcannon commented on Apr 6, 2017

    @brettcannon
    Member

    I consider it an enhancement, especially if someone was sloppy with their tests and explicitly checks the repr of ImportError.

    serhiy-storchaka commented on Apr 13, 2017

    @serhiy-storchaka
    MemberAuthor

    The patch also changes the repr of BaseException with a single argument. It no longer contains a trailing comma.

    berkerpeksag commented on Apr 24, 2017

    @berkerpeksag
    Member

    Including 'path' may make the repr less readable in some cases. +1 for 'name', though.

    remilapeyre commented on Jan 30, 2019

    remilapeyremannequin
    Mannequin

    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__.

    transferred this issue fromon Apr 10, 2022
    added
    3.12only security fixes
    and removed on Oct 29, 2022

    iritkatriel commented on Oct 29, 2022

    @iritkatriel
    Member

    The PRs need to be updated. Marking as easy.

    furkanonder commented on Mar 4, 2023

    @furkanonder
    Contributor

    @iritkatriel PR updated by @arhadthedev I think PR is ready to merge.

    added
    3.13only security fixes
    and removed
    3.12only security fixes
    on Jan 5, 2024

    ynir3 commented on Jul 20, 2025

    @ynir3
    Contributor

    trying to revive this issue by building on the previous PRs #136770

    added a commit that references this issue on Aug 14, 2025

    vstinner commented on Aug 14, 2025

    @vstinner
    Member

    Implemented by c87b66b.

    added a commit that references this issue on Aug 19, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Labels

    easyinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions