Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: "Type[None]" has no attribute "__bool__" #11539

Open
KotlinIsland opened this issue Nov 13, 2021 · 8 comments
Open

error: "Type[None]" has no attribute "__bool__" #11539

KotlinIsland opened this issue Nov 13, 2021 · 8 comments
Labels
bug mypy got something wrong topic-runtime-semantics mypy doesn't model runtime semantics correctly

Comments

@KotlinIsland
Copy link
Contributor

type(None).__bool__
@KotlinIsland KotlinIsland added the bug mypy got something wrong label Nov 13, 2021
@sobolevn
Copy link
Member

We need to add something like

mypy/mypy/checkmember.py

Lines 323 to 329 in 8f281fb

if is_python_3 and name == '__bool__':
literal_false = LiteralType(False, fallback=mx.named_type('builtins.bool'))
return CallableType(arg_types=[],
arg_kinds=[],
arg_names=[],
ret_type=literal_false,
fallback=mx.named_type('builtins.function'))

but for Type[None], PR is on its way! 👍

@KotlinIsland
Copy link
Contributor Author

Would it make sense to use typesheds _typeshed.NoneType for analysis instead of hardcoding it into the typechecker?

@sobolevn
Copy link
Member

_typeshed.NoneType is not standartized. We cannot use it yet 😞

@erictraut
Copy link

FWIW, pyright uses _typeshed.NoneType.

@sobolevn
Copy link
Member

@erictraut do you use any other _typeshed types? 🤔

@erictraut
Copy link

That's the only symbol from _typeshed. We also use _TypedDict from typing, which predates _typeshed but should maybe be moved there.

@JelleZijlstra JelleZijlstra added the topic-runtime-semantics mypy doesn't model runtime semantics correctly label Mar 19, 2022
@ethanhs
Copy link
Collaborator

ethanhs commented Jun 8, 2022

I think we should probably use _typeshed.NoneType or types.NoneType in 3.10+ (which _typeshed.NoneType already handles).

If someone wants to make a PR changing mypy to leverage the _typeshed code, I'd be happy to review it.

@KotlinIsland
Copy link
Contributor Author

KotlinIsland commented Jun 9, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-runtime-semantics mypy doesn't model runtime semantics correctly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants