[BangPypers] Expressing meta-data about classes, methods, variables, parameters in python

Anand Balachandran Pillai abpillai at gmail.com
Thu Apr 3 13:12:03 CEST 2008


No, I don't think so. Python has the trick of "peeking into the future" by
backporting a feature in a future version to the current version by using
the __future__ module.

However I run Python 2.5 and I do not see any mention of function
annotations in __future__ module.

Python 2.5.1 (r251:54863, Sep  6 2007, 17:27:08)
[GCC 4.1.1 20061011 (Red Hat 4.1.1-30)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import __future__
>>> dir(__future__)
['CO_FUTURE_ABSOLUTE_IMPORT', 'CO_FUTURE_DIVISION',
'CO_FUTURE_WITH_STATEMENT', 'CO_GENERATOR_ALLOWED', 'CO_NESTED',
'_Feature', '__all__', '__builtins__', '__doc__', '__file__',
'__name__', 'absolute_import', 'all_feature_names', 'division',
'generators', 'nested_scopes', 'with_statement']
>>>

However, this should be part of Python 2.6.

But why bother ? Best thing to do is check out the Python 3.0 trunk, and
you can build it and get to know this and other Py3k tricks in a matter
of minutes.

Use the following svn URL for Py3k.

http://svn.python.org/projects/python/branches/py3k

HTH.

--Anand

On Thu, Apr 3, 2008 at 4:34 PM, Heshan Suriyaarachchi
<heshan.suri at gmail.com> wrote:
>
> > Hi Anand,
>    This is what I exactly mean. This is the thing I want to do. I am now
> using python 2.5.1 . So is
>     there a way that I can do a thing like this in python 2.5.1 ( an
> alternative way).
>
>   Heshan Suriyaarachchi
>
> >
> >
> > >>> def f(x : "an integer", y: "another integer") -> "Sum of x and y":
> > ...     return x + y
> > >>> f.__annotations__
> > {'y': 'another integer', 'x': 'an integer', 'return': 'Sum of x and y'}
> >
> > The help() function returns the annotation plus the docstring now.
> > >>> f.__doc__ = "A sum function"
> > >>> help(f)
> > Help on function f in module __main__:
> >
> > f(x: 'an integer', y: 'another integer') -> 'Sum of x and y'
> >    A sum function
> >
> >
> >
> >
> >
> >
> >
>
>
> _______________________________________________
>  BangPypers mailing list
>  BangPypers at python.org
>  http://mail.python.org/mailman/listinfo/bangpypers
>
>



-- 
-Anand


More information about the BangPypers mailing list