Skip to content

Cannot instantiate type "Type[None]" #19660

Description

@wyattscarpenter

Bug Report

Mypy claims Cannot instantiate type "Type[None]" when you try to do so. However, you actually can do this in python, and perhaps have been able to do this ever since python 3...

This affects both types.NoneType and type(None). Also, function signatures that get at those.

To Reproduce

https://mypy-play.net/?mypy=master&python=3.12&gist=26b0ab20fc6d45de0edff4f8a374b0a7

from types import NoneType
type(None)()
NoneType()
def f(n: type[None]):
    n()
def g(n: type[NoneType]):
    n()
f(NoneType)
g(NoneType)

Actual Behavior
main.py:2: error: Cannot instantiate type "type[None]" [misc]
main.py:3: error: Cannot instantiate type "type[None]" [misc]
main.py:5: error: Cannot instantiate type "type[None]" [misc]
main.py:6: error: NoneType should not be used as a type, please use None instead [valid-type]
main.py:7: error: Cannot instantiate type "type[None]" [misc]
Found 5 errors in 1 file (checked 1 source file)

Expected Behavior
Running this python file doesn't result in any runtime problems, so I would expect no errors. (Except perhaps main.py:6: error: NoneType should not be used as a type, please use None instead [valid-type], which seems like more of a style suggstion, and so might still be valid.)

Possibly related, perhaps even fixable by this issue: #19308

Activity

  1. added
    bug
    on Aug 14, 2025
  2. hauntsaninja commented on Aug 14, 2025

    @hauntsaninja
    Collaborator

    Look at analyze_type_type_callee

  3. Priyans00 commented on Aug 15, 2025

    @Priyans00

    Hi! If this issue is still available, I’d love to work on it. Could you please assign it to me?

  4. wyattscarpenter commented on Aug 15, 2025

    @wyattscarpenter
    ContributorAuthor

    @Priyans00 go ahead! There is no process for assigning issues in mypy, It's just whoever happens to do to it

  5. codenamenam commented on Sep 2, 2025

    @codenamenam
    Contributor

    I did a PR to fix this issue.
    The fix treats NoneType as a callable returning None.
    I have also added a test case testTypeUsingTypeCNoneType which covers direct calls and function parameters accepting type[None] and type[NoneType].
    This change ensures proper handling of NoneType instantiation without errors.

  6. LeoLomardo commented on Oct 14, 2025

    @LeoLomardo

    Is this issue still open? Im learning to contribute on open source projects and i looking foward to find a issue to solve

  7. wyattscarpenter commented on Oct 14, 2025

    @wyattscarpenter
    ContributorAuthor

    @LeoLomardo thanks for your interest. I think the extant pull request solves this one, though, and it just hasn't been merged yet.

    Here are some other candidates for issues that might be sort of easyish for a newcomer to the project to solve, in my humble opinion, which I hope may be of useful to you. Keep in mind that by the time you look at them they may have proposed pull requests that already fix them:

    • Things in the good-first-issue tag
    • Things in the good-second-issue tag

    Test infrastructure:

    At this point I got bored of writing and realized that the list I was assembling was idiosyncratic anyway, and not much better than just looking at the issues list and thinking "which one of these is probably not too much trouble?".

  8. added a commit that references this issue on Mar 14, 2026
    44ac462
  9. added a commit that references this issue on May 2, 2026
    b92de51
  10. iamajaykr06 commented on Jul 15, 2026

    @iamajaykr06

    "Hi, I'd like to work on this. Could you assign it to me?" This avoids duplicate work with someone else.

  11. added a commit that references this issue on Oct 21, 2026
    73d7fb1
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

    buggood-first-issue

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions