On Sat, 13 Feb 2021 at 07:11, Steven D'Aprano <st...@pearwood.info> wrote:
>
> On Fri, Feb 12, 2021 at 10:27:01AM +0000, Mark Shannon wrote:
>
> > It impairs readability, because it muddles the return type.
> > The function in the example returns a bool.
> > The annotation is also misleading as the annotation is on the return
> > type, not on the parameter that is narrowed.
> >
> > At a glance, most programmers should be able to work out what
> >
> > def is_str_list(val: List[object]) -> bool:
> >
> > returns.
> >
> > But,
> >
> > def is_str_list(val: List[object]) -> TypeGuard[List[str]]:
> >
> > is likely to confuse and require careful reading.
> > Type hints are for humans as well as type checkers.
>
> This!
>
> Without reading the PEP, how is anyone supposed to know that this
> returns a bool?

I have to agree here. I'm not a frequent user of type hints yet, but I
am starting to have to maintain code that has type hints, and from a
maintenance perspective, I have to say that this would be really hard
to deal with. If I saw this for the first time "in the wild", I'd have
no idea what to do with it.

Paul
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/43A7TU2VYDIGFP3THLDFFUWJGWSZSIEM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to