[Python-ideas] Conventions for function annotations
Bruce Leban
bruce at leapyear.org
Thu Dec 6 01:13:51 CET 2012
On Wed, Dec 5, 2012 at 3:01 PM, Guido van Rossum <guido at python.org> wrote:
>
> Those are not the semantics I had in mind for Optional.
I know that. My point was that the standard meaning of the word optional is
that something may or may not be given (or whatever the applicable verb
is). That's quite different from saying it must be provided but may be
None. Since you invited a bit of bikeshedding, I felt it was appropriate to
point that out and then I got distracted by discussing the alternative that
you weren't talking about. Sorry that was confusing.
In C#, this is called Nullable and you can write Nullable<String> to
indicate the type (String or null type). The shorthand for that is String?.
If you want a shorthand to specify that None is allowed, I'd suggest ~Str.
--- Bruce
P.S. Optional[T] is not literally a shorthand for T | None as the former is
11 characters and the latter is 10 characters even if we include and count
the spaces. :-)
P.P.S. I don't think Str | None rather than Str | NoneType is confusing.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20121205/117ce778/attachment.html>
More information about the Python-ideas
mailing list