On Thu, Feb 11, 2021 at 12:00 AM Jim J. Jewett <jimjjew...@gmail.com> wrote:
> (1) Is it really a TypeGuard, or more of a TypeAssertion? > It's a query, not an assertion. The same concept is called type guard in TypeScript. > (2) Does this push too hard on "annotations only have one meaning"? If > it has to imported from typing, then probably not, but I think that is > worth adding to the PEP. > No. *This* particular annotation has a meaning for static type checkers. If you use annotations for something else, don't use it. > (3) Why can't the falsey case of an Optional String narrow to a set of > literals {"", None} Are you worried that a subclass of str might have its > own empty string, or just that you don't want to promise this? As written, > it sounds like such a narrowing is forbidden. > A type checker could do this, but I don't see a reason why we should prescribe that type checkers *should* do that. Some type checkers (in particular, mypy) are reluctant to infer union types, and there are good reasons for this (but this margin isn't wide enough to explain it). -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________ 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/TZ6UZAPFX7OG64PFMQUZKDPBVYD6A5WK/ Code of Conduct: http://python.org/psf/codeofconduct/