On 10 Feb 2016, at 5:52 pm, Guido van Rossum <gu...@python.org> wrote: > > On Wed, Feb 10, 2016 at 1:11 AM, Phil Thompson > <p...@riverbankcomputing.com> wrote: >> I understand now. The documentation, as it stands, is correct and consistent >> but (to me) the meaning of Optional is completely counter-intuitive. What >> you suggest with str = ... is exactly what I need. Adding a section to the >> docs describing that should clear up the confusion. > > I tried to add some clarity to the docs with this paragraph: > > Note that this is not the same concept as an optional argument, > which is one that has a default. An optional argument with a > default needn't use the ``Optional`` qualifier on its type > annotation (although it is inferred if the default is ``None``). > A mandatory argument may still have an ``Optional`` type if an > explicit value of ``None`` is allowed. > > Should be live on docs.python.org with the next push (I don't recall > the delay, at most a day IIRC).
That should do it, thanks. A followup question... Is... def foo(bar: str = Optional[str]) ...valid? In other words, bar can be omitted, but if specified must be a str or None? Thanks, Phil _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com