Thanks Eric for the PEP. I have some questions:
Type checkers should assume that type narrowing should be applied to the expression that is passed as the first argument to a user-defined type guard.
What should happen in case of instance methods, class methods or static methods? The first two cases have an implicit self/class argument? Would the type guyard apply to that argument or to the first explicit parameter?
What about properties? Would they be supported?
User-defined type guards apply narrowing only in the positive case (the if clause).
Like Sebastian Rittau mentioned, what is the rationale behind this?
We talked about this on gitter, but I'll sum it up here as well. I think `filter` could be modified to use a guard:
def filter(__function: Callable[[_T1], TypeGuard[_T2]], __iterable: Iterable[_T1]) -> Iterator[_T2]: ...
Unfortunately, you have to encode the narrowing behavior into the signature (as there's no code flow graph), but I suppose this makes some sense.
`filterfalse`, not so much, because the way `TypeGuard` has to work only allows proving of truths. You mentioned TS's `Exclude`, which would allow proving of truths by having a `TypeGuard` that could say something like "I prove that the type of the first parameter is not of type `_T2`", for example.
Typing-sig mailing list -- email@example.com
To unsubscribe send an email to firstname.lastname@example.org
Member address: email@example.com