On Wed, Apr 7, 2021 at 12:21 AM Federico Salerno <salernof11@gmail.com> wrote:

I don't have any decent proposal at the moment but I think coming up with a way to annotate side-effects of functions (including typeguard-ness) could come in handy. If we anticipate needing that, perhaps it would be beneficial to come up with that feature before implementing this PEP, lest we end up with something that could have benefitted from it but was released just before it.

Though personally I like the PEP and have no qualms about having to learn that TypeGuard is "a bool with a side-effect"; I don't think it's a problem in the first place, there are less obvious, more complicated things in Python that I couldn't just intuit at a glance.


But it isn't a "side effect". It is a distinct concept that is important to the type checker.

Note that in TypeScript this also doesn't look like a boolean -- it uses a unique syntax that has to be learned:

function isCustomer(partner: any): partner is Customer {
    . . .
}

Arguably the TS syntax is more easily intuited without looking it up, but TS has a certain freedom in its syntactic design that we don't have for Python: new *syntax* has to be added to the Python parser and can't be backported, whereas new *types* (like `TypeGuard[T]`) can easily be backported via typing_extensions.py.

We have really tried, but we did not come up with anything better than the current PEP.

FWIW you might be interested in Annotated (PEP 593), which can be used to indicate various attributes of a type annotation. Before you suggest that we adopt that instead of PEP 647, we considered that, and the consensus is that that's not what Annotated is for (it's intended for conveying information to tools *other* than the type checker, for example schema checkers etc.).

--
--Guido van Rossum (python.org/~guido)