You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 25, 2020. It is now read-only.
This is Issue 19 moved from a Google Code project.
Added by 2009-09-09T17:10:56.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Original labels: Type-Enhancement, Priority-Low, Usability
Original description
Starting with Python3, you can add 'annotations' to function arguments.
>>> def foo(a:int, b:"hello"): pass
...
>>> foo.__annotations__
{'a': <class 'int'>, 'b': 'hello'}
>>>
A new optparser alternative called "pyopt" makes use of this feature to
make writing optparser definitions in a seamless way: http://
code.google.com/p/pyopt/wiki/Examples
For example,
@expose.kwargs
def bigfun(brightness:int, nudge:bool, happy:bool, shaft:str='gold'):
"""
bigfun is a keyword command-line function.
Switches can be given in any order.
Also, booleans can be combined ie: -nh
-b --brightness - how bright is it outside on a scale of 1-10
-n --nudge - are you nudging me?
-h --happy - script should be happy.
-s --shaft - what kind of shaft are you?
"""
That is there is to it. The option type and option default value are
probably derived from the typed annotation (int, bool, str) while the
short string and long string (-s, --brightness) including option help doc
are automatically "extracted" from the docstring of the function. Me likes
this.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
This is Issue 19 moved from a Google Code project.
Added by 2009-09-09T17:10:56.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.
Original labels: Type-Enhancement, Priority-Low, Usability
Original description
The text was updated successfully, but these errors were encountered: