Skip to content

Convert None to NoneType in the union type constructor #88801

Closed

Description

@serhiy-storchaka
BPO 44635
Nosy @gvanrossum, @serhiy-storchaka, @Fidget-Spinner
PRs
  • bpo-44635: Convert None to NoneType in the union type constructor #27136
  • [3.10] bpo-44635: Convert None to NoneType in the union type constructor (GH-27136) #27141
  • [3.10] bpo-44635: Convert None to NoneType in the union type constructor (GH-27136). #27142
  • 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 = <Date 2021-07-15.07:15:55.473>
    created_at = <Date 2021-07-14.10:51:57.968>
    labels = ['interpreter-core', 'type-feature', '3.10', '3.11']
    title = 'Convert None to NoneType in the union type constructor'
    updated_at = <Date 2021-07-15.07:15:55.473>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2021-07-15.07:15:55.473>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-07-15.07:15:55.473>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2021-07-14.10:51:57.968>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44635
    keywords = ['patch']
    message_count = 3.0
    messages = ['397475', '397496', '397525']
    nosy_count = 3.0
    nosy_names = ['gvanrossum', 'serhiy.storchaka', 'kj']
    pr_nums = ['27136', '27141', '27142']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue44635'
    versions = ['Python 3.10', 'Python 3.11']

    Activity

    1. serhiy-storchaka commented on Jul 14, 2021

      @serhiy-storchaka
      MemberAuthor

      There is a difference between typing.Union and the builtin union type in representing None in __args__:

      >>> import typing
      >>> typing.Union[int, None].__args__
      (<class 'int'>, <class 'NoneType'>)
      >>> typing.Union[int, type(None)].__args__
      (<class 'int'>, <class 'NoneType'>)
      >>> (int | None).__args__
      (<class 'int'>, None)
      >>> (int | type(None)).__args__
      (<class 'int'>, <class 'NoneType'>)

      The former converts None to NoneType, the latter leaves it as is, and only performs conversion in __instancecheck__ and __subclasscheck__. In the discussion for bpo-44606 it was proposed to convert None to NoneType in the union type constructor to make more uniform with typing.Union and simplify __instancecheck__ and __subclasscheck__.

    2. added
      3.10 (EOL)
      3.11
      interpreter-core
      type-feature
      on Jul 14, 2021
    3. serhiy-storchaka commented on Jul 14, 2021

      @serhiy-storchaka
      MemberAuthor

      New changeset b81cac0 by Serhiy Storchaka in branch 'main':
      bpo-44635: Convert None to NoneType in the union type constructor (GH-27136)
      b81cac0

    4. serhiy-storchaka commented on Jul 15, 2021

      @serhiy-storchaka
      MemberAuthor

      New changeset 6dec525 by Serhiy Storchaka in branch '3.10':
      [3.10] bpo-44635: Convert None to NoneType in the union type constructor (GH-27136). (GH-27142)
      6dec525

    5. transferred this issue fromon Apr 10, 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.10 (EOL)3.11interpreter-coretype-feature

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions