On Mon, Mar 9, 2009 at 23:35, Dan Korostelev <nadako@gmail.com> wrote:
I don't think they are, according to PEP 3107 they are stored in the func_annotations attribute of the function.
No, they are stored in __annotations__. Look here: http://docs.python.org/3.0/whatsnew/3.0.html#new-syntax
Also:
nyo@seasaw:~$ python3 Python 3.0.1+ (r301:69556, Feb 24 2009, 13:51:44) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information.
def hello(who:'name') -> None: ... print('Hello, {0}!'.format(who)) ... hello.__annotations__ {'who': 'name', 'return': None}
Interesting! Perhaps we should file a bug to have the PEP updated with reality then. ;-)
Note that even if the name *where* the same, attribute annotations only work on classes and instances, while function annotations only apply to functions, not?
Good point. Looks like it is added automatically only for functions/methods. :)
However, we can't be sure there won't be annotations for any callable object, because even PEP says that ``we say function, we mean callable object``, so one day we certainly will conflict with something. Also, as Gary pointed out, we mis-use the __*__ name pattern that is now intended for defining special names that have special meaning for python interpreter. And we'll certainly will mis-use the __annotations__ name as it's clearly defined in python 3k.
So, after Gary reminded about __*__ names, I think we shoud use something like "_z_annotations".
Semi-agreed. Tools that access ZODB objects and expect __annotations__ to follow the PEP 3107 conventions will be quite surprised. I doubt that there will be many tools to do so though. Then again, if Python is now explicitly claiming the __*__ naming convention, Zope better avoid it's usage. This means we'll have to fix __parent__ and __name__ usage as well. This will be painful, me thinks.. -- Martijn Pieters