Skip to content

NoneType is basically deprecated but None behaves differently #129816

@justinvanwinkle

Description

@justinvanwinkle

Bug report

Bug description:

python 3.13

# Add a code block here, if required

>>> from types import NoneType
>>> None | int
None | int

>>> int | None
int | None

>>> None | int == int | None
True

>>> NoneType | int == None | int
True

>>> NoneType | NoneType
<class 'NoneType'>

>>> NoneType | NoneType == NoneType
True

>>> from typing import Union

>>> Union[None, None]
<class 'NoneType'>

>>> NoneType | None
<class 'NoneType'>

>>> None | NoneType
<class 'NoneType'>

>>> Union[None, NoneType]
<class 'NoneType'>

>>> None | None
Traceback (most recent call last):
  File "<python-input-50>", line 1, in <module>
    None | None
    ~~~~~^~~~~~
TypeError: unsupported operand type(s) for |: 'NoneType' and 'NoneType'

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedtopic-typingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions