FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Type narrowing fails on type(None) or NoneType · Issue #19308 · python/mypy · GitHub

Repository navigation

Type narrowing fails on type(None) or NoneType #19308

Open

Description

Bug Report

Type narrowing can't remove type(None) from a union.

To Reproduce

def get_class(x: int) -> type[str | None]:
    if x > 0:
        return str
    else:
        return type(None)


x = get_class(1)
if x is type(None):
    print("hi")
else:
    x("test") # Cannot instantiate type "Type[None]"

Expected Behavior

Type narrowing should eliminate that possibility. It works with None, but not NoneType.

Actual Behavior

Cannot instantiate type "Type[None]"

Your Environment

mypy 1.16.0
Python 3.12.10

Activity

  1. added and removed
    bugmypy got something wrong
    on Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL