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

Now type(None) is more consistent, refs #11550 #11552

Closed
wants to merge 2 commits into from
Closed

Now type(None) is more consistent, refs #11550 #11552

wants to merge 2 commits into from

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Nov 14, 2021

Closes #11550

This might fail in some unexpected cases.

@@ -2686,6 +2686,8 @@ def check_and_set_up_type_alias(self, s: AssignmentStmt) -> bool:

res: Optional[Type] = None
if self.is_none_alias(rvalue):
# This is really `Type[None]`, not just `None`, but we use
# this as a backwards compatible solution. See #11550
res = NoneType()
Copy link
Member Author

@sobolevn sobolevn Nov 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can still cause issues, for example:

none = type(None)

print(none())  # E: error: Cannot instantiate type "Type[None]"

But, I've decided to keep this as-is (and do not change this to res = TypeType(NoneType())), because I'm affraid this can cause issues to our old users, who use type(None) for annotations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we decide to change this, we can try to make Type[None] and None compatible. So, this will work:

n = type(None)
var: n = None  # will still be ok!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think types that are none should be annotated None. If someone tries to annotate something that is none as type(None) we should give an error and tell them to annotate it as : None (though I also expect this to be rather rare).

@sobolevn
Copy link
Member Author

Related #11551

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

reveal_type(type(None)) is object
2 participants