On 10 Feb 2016, at 5:52 pm, Guido van Rossum <guido at python.org> wrote: > > On Wed, Feb 10, 2016 at 1:11 AM, Phil Thompson > <phil at 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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4