On Fri, Feb 12, 2021 at 12:14 PM Jim J. Jewett <jimjjew...@gmail.com> wrote:

> Current PEP 647 draft says:
>
> "Some built-in type guards provide narrowing for both positive and
> negative tests (in both the if and else clauses)"
>
> Should there be a separate (sub-?) type for those TypeGuards that *do*
> allow narrowing even on a False?  Leaving it as an implementation detail
> available only to (some) built-in types seems to confuse the issue in both
> directions.
>

I think the PEP is using the term in a wider sense here, referring to
things like `isinstance(x, C)` and `x is not None`. Note that mypy (at
least) also recognizes `if x:` as narrowing `Optional[T]` to `T`, but there
in the else clause we *cannot* assume that x is not a T, because it could
be a falsey instance.

-- 
--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/ZTKR6ZQF5PKR26HJICHMA2VPLQMNKMOH/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to