I don't find this example particularly compelling. `TypeGaurd` is not an instantiable type. A function that returns `TypeGaurd[T]` in actuality returns `bool`:
"""
Return statements within a type guard function should return bool values, and type checkers should verify that all return paths return a bool.
"""
So this issue of overloading seems pretty irrelevant.
I found this confusing too, until I looked further into the overload rules and overlapping with classes. Consider this reduced example:
```
from typing import Union, overload
class bool: ...
class TypeGuard(bool): ... # Illegal, but pretend it is okay.
@overload
def func(x: TypeGuard) -> int: ...
@overload
def func(x: bool) -> str: ...
def func(x: Union[TypeGuard, bool]) -> Union[int, str]:
if isinstance(x, TypeGuard):
return 1234
return "hey"
```
If I then write:
```
def do_something() -> bool: return TypeGuard()
b: bool = do_something()
x = func(b)
```
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`.
See also: https://github.com/python/typing/issues/253#issuecomment-389262904
_______________________________________________
Typing-sig mailing list -- typing-sig@python.org
To unsubscribe send an email to typing-sig-leave@python.org
https://mail.python.org/mailman3/lists/typing-sig.python.org/
Member address: donovick@cs.stanford.edu