[Python-ideas] typing.Maybe type annotation

2021-03-09 Thread Ben Avrahami
Hi all, I recently ran into a problem trying to adapt mypy into an older codebase, and it got me thinking about a potential addition to the typing library. This idea comes in two parts (that can even be taken individually): the first is to allow the False singleton literal to be used in type annot

[Python-ideas] Re: typing.Maybe type annotation

2021-03-09 Thread Chris Angelico
On Tue, Mar 9, 2021 at 9:15 PM Ben Avrahami wrote: > raw_value : str = input() > # suppose we want to convert raw_value to an int, but leave it as an > arbitrary falsish value if raw_value is an empty string, we can now do this > in the following ways: > # annotate value as a union (type hint is

[Python-ideas] Re: typing.Maybe type annotation

2021-03-09 Thread Steven D'Aprano
I was astonished that `typing.Maybe[T]` doesn't already exist, but if it did exist, surely it would have to be `Union[T, None]`. Ah wait, that would be spelled "Optional". As for the pseudo-type `False` meaning "any falsey value", I don't think that tracking the *value* of variables is somethin