[Python-Dev] PEP 484 proposal: don't default to Optional if argument default is None

Brett Cannon brett at python.org
Tue May 9 18:51:34 EDT 2017


On Tue, 9 May 2017 at 11:11 Carl Meyer <carl at oddbird.net> wrote:

> On 05/09/2017 10:28 AM, Guido van Rossum wrote:
> > There's a proposal to change one detail of PEP 484. It currently says:
> >
> >     An optional type is also automatically assumed when the default
> value is
> >     |None|, for example::
> >
> >     |def handle_employee(e: Employee = None): ... |
> >
> >     This is equivalent to::
> >
> >     |def handle_employee(e: Optional[Employee] = None) -> None: ... |
> >
> >
> > Now that we've got some experience actually using Optional with mypy
> > (originally mypy ignored Optional), we're beginning to think that this
> > was a bad idea. There's more discussion at
> > https://github.com/python/typing/issues/275 and an implementation of the
> > change (using a command-line flag) in
> > https://github.com/python/mypy/pull/3248.
> >
> > Thoughts? Some function declarations will become a bit more verbose, but
> > we gain clarity (many users of annotations don't seem to be familiar
> > with this feature) and consistency (since this rule doesn't apply to
> > variable declarations and class attribute declarations).
>
> I've been code-reviewing a lot of diffs adding type coverage over the
> last few months, and implicit-Optional has been among the most common
> points of confusion. So I favor this change.
>

I personally like the shorthand, but the type hints I have written are in
my own projects so my experience with others is zilch and shouldn't count
for much.


>
> It might be nice to have a less verbose syntax for Optional, but that
> can be a separate discussion.
>

You should be able to do that today with `from typing import Optional as
Eh` or whatever your preferred optional/maybe name is. :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20170509/7cc4b475/attachment-0001.html>


More information about the Python-Dev mailing list