Skip to content

(🎁) Warn when NoneType is used in a type #11288

Closed
@KotlinIsland

Description

@KotlinIsland

NoneType is a mangled up mess in the type realm and should never be used in a typing context.

With the special case of None being a secret alias to NoneType I think that many, many people are going to try to use NoneType as an annotation. Adding a warning for the 99% of the time that it's invalidly used would be a great one.

I understand that there are always edge cases, and disabling those warnings with a type comment would be the way to go IMO.

from types import NoneType

def foo(a: NoneType):  # sus alert, NoneType is a mess in the type realm, you should use `None` or `type[None]` instead.
    print(isinstance(a, NoneType))

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions