Closed KotlinIsland closed 1 year ago
@AlexWaygood
Can you delete / report this AI spam comment.
https://github.com/python/mypy/issues/16146#issuecomment-1730198641
@AlexWaygood
Can you delete / report this AI spam comment.
Sadly not; I'm not a maintainer at mypy, and editing/deleting comments requires more than my triage privileges. Otherwise I would.
Reported and deleted the comment, will hide your comments and mine as off-topic.
PEP doesn't cover this case, but it is obviously incorrect.
Isn't it? The PEP says that narrowing will be performed on the first explicit argument passed to the TypeGuard function, and that is the explicitly passed self on an instance method accessed via its class.
It's not a very good TypeGuard since it can just be a freestanding function, but it does seem to be PEP compliant...
This code sample uses a user-defined type guard function in a manner for which it wasn't designed and I wouldn't recommend. That said, I think that mypy is behaving correctly here and is in compliance with PEP 647, so I don't consider this a bug. Note: I'm the author of PEP 647.
The PEP says that the expression passed as the first positional argument to the call should be narrowed. In your example, the first positional argument in the call expression A.f(a, c)
is a
. Mypy behaving in accordance with the text of the PEP. It's also working consistently with pyright, which is the reference implementation for PEP 647.
PEP doesn't cover this case, but it is obviously incorrect.