Skip to content

Replace type(literal) with corresponding builtin types #88878

Closed

Description

@serhiy-storchaka
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']

    Activity

    1. serhiy-storchaka commented on Jul 22, 2021

      @serhiy-storchaka
      MemberAuthor

      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.

    2. added
      3.11only security fixes
      stdlibStandard Library Python modules in the Lib/ directory
      on Jul 22, 2021
    3. serhiy-storchaka commented on Jul 22, 2021

      @serhiy-storchaka
      MemberAuthor

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

    4. transferred this issue fromon Apr 10, 2022
    5. added 2 commits that reference this issue on Aug 8, 2022
    6. added 2 commits that reference this issue on Aug 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.11only security fixesstdlibStandard Library Python modules in the Lib/ directory

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions