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

Convert None to NoneType in the union type constructor #88801

Closed
serhiy-storchaka opened this issue Jul 14, 2021 · 3 comments
Closed

Convert None to NoneType in the union type constructor #88801

serhiy-storchaka opened this issue Jul 14, 2021 · 3 comments
Labels
3.10 only security fixes 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

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']

    @serhiy-storchaka
    Copy link
    Member Author

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

    @serhiy-storchaka serhiy-storchaka added 3.10 only security fixes 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Jul 14, 2021
    @serhiy-storchaka
    Copy link
    Member Author

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

    @serhiy-storchaka
    Copy link
    Member Author

    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

    @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
    3.10 only security fixes 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant