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?

On Wed, Oct 21, 2020 at 2:41 PM Jake Bailey via Typing-sig <> wrote:
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 --
To unsubscribe send an email to
Member address:

Sebastian Kreft