Repository navigation
Use --strict for selfcheck - #13464
Conversation
This comment has been minimized.
This comment has been minimized.
| 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.
I am just curious: why != here does not return bool?
There was a problem hiding this comment.
| 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.
How do you decide between cast and assert? 🤔
There was a problem hiding this comment.
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.
__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.
sobolevn
left a comment
There was a problem hiding this comment.
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.