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

Replace type(literal) with corresponding builtin types #88878

Closed
serhiy-storchaka opened this issue Jul 22, 2021 · 2 comments
Closed

Replace type(literal) with corresponding builtin types #88878

serhiy-storchaka opened this issue Jul 22, 2021 · 2 comments
Labels
3.11 bug and security fixes stdlib Python modules in the Lib dir

Comments

@serhiy-storchaka
Copy link
Member

BPO 44712
Nosy @serhiy-storchaka
PRs
  • bpo-44712: Replace "type(literal)" with corresponding builtin types #27294
  • 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 = None
    closed_at = None
    created_at = <Date 2021-07-22.20:41:11.966>
    labels = ['library', '3.11']
    title = 'Replace `type(literal)` with corresponding builtin types'
    updated_at = <Date 2021-07-22.20:54:43.782>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2021-07-22.20:54:43.782>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2021-07-22.20:41:11.966>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44712
    keywords = ['patch']
    message_count = 2.0
    messages = ['398002', '398003']
    nosy_count = 1.0
    nosy_names = ['serhiy.storchaka']
    pr_nums = ['27294']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue44712'
    versions = ['Python 3.11']

    @serhiy-storchaka
    Copy link
    Member Author

    There are several occurrences of type(literal) in the code of the stdlib where literal is a literal of built-in type: '', 1, [], {}, etc. I suppose it is a remnants of very old code written when str, int, list, dict, etc were functions and not classes.

    The proposed PR replaces type(literal) with corresponding builtin types. It makes the code cleaner.

    I consider also idea of replacing identity or equality checks ("is" or "==") with isinstance(). I suppose that that code was written when built-in types were not subclassable. But now there is a reason to use isinstance().

    See also bpo-44711.

    @serhiy-storchaka serhiy-storchaka added 3.11 bug and security fixes stdlib Python modules in the Lib dir labels Jul 22, 2021
    @serhiy-storchaka
    Copy link
    Member Author

    All cases was manually checked several times (with months passes between checks). Several cases were preserved: when the name of built-in type conflicted with the name of function parameter (in weakref.py), when the code was used for testing type() and when the test code looks clearer with type(literal).

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    terryjreedy added a commit to terryjreedy/cpython that referenced this issue Aug 8, 2022
    Change in idlelib.browser, line 54
    cherrypicked from 3680ebe
    terryjreedy added a commit that referenced this issue Aug 9, 2022
    Change in idlelib.browser, line 54
    cherrypicked from 3680ebe
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 9, 2022
    Change in idlelib.browser, line 54
    cherrypicked from 3680ebe
    (cherry picked from commit 1a22ec5)
    
    Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
    miss-islington added a commit that referenced this issue Aug 9, 2022
    Change in idlelib.browser, line 54
    cherrypicked from 3680ebe
    (cherry picked from commit 1a22ec5)
    
    Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 bug and security fixes stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant