Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer using __spec__ over module_repr() for ModuleType.__repr__ #86303

Closed
brettcannon opened this issue Oct 23, 2020 · 5 comments
Closed

Prefer using __spec__ over module_repr() for ModuleType.__repr__ #86303

brettcannon opened this issue Oct 23, 2020 · 5 comments
Assignees
Labels
interpreter-core type-bug

Comments

@brettcannon
Copy link
Member

@brettcannon brettcannon commented Oct 23, 2020

BPO 42137
Nosy @brettcannon
PRs
  • #24953
  • 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/brettcannon'
    closed_at = <Date 2021-03-24.15:27:17.592>
    created_at = <Date 2020-10-23.23:20:55.502>
    labels = ['interpreter-core', 'type-bug']
    title = 'Prefer using __spec__ over module_repr() for ModuleType.__repr__'
    updated_at = <Date 2021-03-24.15:27:17.591>
    user = 'https://github.com/brettcannon'

    bugs.python.org fields:

    activity = <Date 2021-03-24.15:27:17.591>
    actor = 'brett.cannon'
    assignee = 'brett.cannon'
    closed = True
    closed_date = <Date 2021-03-24.15:27:17.592>
    closer = 'brett.cannon'
    components = ['Interpreter Core']
    creation = <Date 2020-10-23.23:20:55.502>
    creator = 'brett.cannon'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42137
    keywords = ['patch']
    message_count = 5.0
    messages = ['379496', '389177', '389206', '389326', '389470']
    nosy_count = 1.0
    nosy_names = ['brett.cannon']
    pr_nums = ['24953']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue42137'
    versions = []

    @brettcannon
    Copy link
    Member Author

    @brettcannon brettcannon commented Oct 23, 2020

    Once all traces of module_repr() are gone, raise an ImportWarning when using module_repr().

    Once this is implemented and has been out in the wild for a sufficient amount of time, it should be switching to a DeprecationWarning and then the fallback eventually removed.

    @brettcannon brettcannon added interpreter-core type-bug labels Oct 23, 2020
    @brettcannon
    Copy link
    Member Author

    @brettcannon brettcannon commented Mar 20, 2021

    Should try to use __spec__ first, but if it isn't set then fall back on module_repr() and raise an ImportWarning. See Lib/importlib/_bootstrap.py:_module_repr.

    @brettcannon
    Copy link
    Member Author

    @brettcannon brettcannon commented Mar 21, 2021

    Thinking about it more, raising ImportWarning (or DeprecationWarning) is unnecessarily noisy as the existence of the module isn't problematic, it just won't be used anymore in the future. So updating the code to use __spec__ first and then document in "What's New" should be good enough.

    @brettcannon brettcannon changed the title Raise an ImportWarning for calling module_repr() on loaders Prefer using __spec__ over module_repr() for ModuleType.__repr__ Mar 21, 2021
    @brettcannon brettcannon self-assigned this Mar 21, 2021
    @brettcannon brettcannon changed the title Raise an ImportWarning for calling module_repr() on loaders Prefer using __spec__ over module_repr() for ModuleType.__repr__ Mar 21, 2021
    @brettcannon brettcannon self-assigned this Mar 21, 2021
    @brettcannon
    Copy link
    Member Author

    @brettcannon brettcannon commented Mar 22, 2021

    Meant to say, "existence of the _method_ isn't problematic".

    @brettcannon
    Copy link
    Member Author

    @brettcannon brettcannon commented Mar 24, 2021

    New changeset 9cb31d6 by Brett Cannon in branch 'master':
    bpo-42137: have ModuleType.__repr__ prefer __spec__ over module_repr() (GH-24953)
    9cb31d6

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core type-bug
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant