-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Use --strict
for selfcheck
#13464
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
Conversation
This comment has been minimized.
This comment has been minimized.
@@ -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) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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
? 🤔
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
Let's wait for one more :)
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Thanks @sobolevn and @JelleZijlstra! |
The only check that wasn't already enabled was
--warn-return-any
.