On 3/17/21, 5:31 PM, "Jake Bailey via Typing-sig" email@example.com wrote:
I found this confusing too, until I looked further into the overload rules and overlapping with classes. ... If we say "it's a `bool`" and attempt to pick the second overload, it will be wrong, because at runtime it's `TypeGuard`, and `func` returns an `int`, not the expected `str`.
This seems like an orthogonal issue with overloads (or with invalid assumptions made in that particular use of overload); what is specific to TypeGuard about it? The example code would exhibit the same behavior if you used two arbitrary classes `A` and `B(A)` instead of `bool` and `TypeGuard(bool)`.
It doesn't seem like this example alone should be a reason for `Callable[..., TypeGuard]` to not be assignable to `Callable[..., bool]`.
Since the inability to use type guards as filter predicates is likely to recur as an FAQ for users of TypeGuard, I would suggest that if there is a strong reason for it, the PEP should provide that reason, perhaps as an entry in the "Rejected Ideas" section. Currently as far as I can see the PEP provies no rationale for that choice.