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

Use --strict for selfcheck #13464

Merged
merged 4 commits into from Aug 26, 2022
Merged

Use --strict for selfcheck #13464

merged 4 commits into from Aug 26, 2022

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Aug 20, 2022

The only check that wasn't already enabled was --warn-return-any.

@github-actions

This comment has been minimized.

mypy/literals.py Outdated Show resolved Hide resolved
mypy/literals.py Outdated Show resolved Hide resolved
@@ -569,7 +569,7 @@ def get_type(arg: Any) -> str | None:

def has_default(arg: Any) -> bool:
if isinstance(arg, inspect.Parameter):
return arg.default != inspect.Parameter.empty
return bool(arg.default != inspect.Parameter.empty)
Copy link
Member

@sobolevn sobolevn Aug 21, 2022

Choose a reason for hiding this comment

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

I am just curious: why != here does not return bool?

Copy link
Member Author

@AlexWaygood AlexWaygood Aug 21, 2022

Choose a reason for hiding this comment

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

@@ -2587,7 +2587,7 @@ class EllipsisType(ProperType):

def accept(self, visitor: TypeVisitor[T]) -> T:
assert isinstance(visitor, SyntheticTypeVisitor)
return visitor.visit_ellipsis_type(self)
return cast(T, visitor.visit_ellipsis_type(self))
Copy link
Member

@sobolevn sobolevn Aug 21, 2022

Choose a reason for hiding this comment

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

How do you decide between cast and assert? 🤔

Copy link
Member Author

@AlexWaygood AlexWaygood Aug 21, 2022

Choose a reason for hiding this comment

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

I would generally use assert wherever possible, as it provides runtime verification of the type narrowing. cast feels closer to telling the type checker to shut up and go away 😄

But here, we can't use assert — how can we assert that something is of type T, when we don't know what T is (since T is a TypeVar)? And this also feels like somewhere where, ideally, mypy should be able to infer that the returned type is of type T without any manual type narrowing. So in this specific situation, I'm more at ease with telling the type checker to shut up and go away 😉

# Handle __class__ so that isinstance still works...
if attr == "__class__":
return object.__getattribute__(self, attr)
return object.__getattribute__(self, attr) # type: ignore[no-any-return]
Copy link
Member Author

@AlexWaygood AlexWaygood Aug 21, 2022

Choose a reason for hiding this comment

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

__getattribute__ feels like it could be quite performance-sensitive, so type: ignore feels like the best option here imo.

@AlexWaygood AlexWaygood requested a review from sobolevn Aug 21, 2022
@github-actions

This comment has been minimized.

Copy link
Member

@sobolevn sobolevn left a comment

LGTM, thank you!

Let's wait for one more :)

@github-actions
Copy link

github-actions bot commented Aug 25, 2022

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra merged commit 0406826 into python:master Aug 26, 2022
18 checks passed
@AlexWaygood AlexWaygood deleted the selfcheck branch Aug 26, 2022
@AlexWaygood
Copy link
Member Author

AlexWaygood commented Aug 26, 2022

Thanks @sobolevn and @JelleZijlstra!

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.

None yet

3 participants