You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
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.
@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:
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?".
Activity
hauntsaninja commentedon Aug 14, 2025
Look at
analyze_type_type_calleePriyans00 commentedon Aug 15, 2025
Hi! If this issue is still available, I’d love to work on it. Could you please assign it to me?
wyattscarpenter commentedon Aug 15, 2025
@Priyans00 go ahead! There is no process for assigning issues in mypy, It's just whoever happens to do to it
codenamenam commentedon Sep 2, 2025
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.
LeoLomardo commentedon Oct 14, 2025
Is this issue still open? Im learning to contribute on open source projects and i looking foward to find a issue to solve
wyattscarpenter commentedon Oct 14, 2025
@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:
Test infrastructure:
--update-dataremoves escapes #17465--update-dataintroduces new blank lines when aligning multi-line expected info comments #19940 (My PR on this only adds failing tests; you're welcome to work on it to add a fix — perhaps using my tests!)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?".
Fix false positive "Cannot instantiate type[None]" error
Fix: allow instantiating type[None] and type(None)
iamajaykr06 commentedon Jul 15, 2026
"Hi, I'd like to work on this. Could you assign it to me?" This avoids duplicate work with someone else.
Allow instantiation of type[None] (python#19782)