Six

Decorators for function annotations

Bug #609598 reported by Dag Odenhall
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Six
Won't Fix
Wishlist
Unassigned

Bug Description

I propose the addition of decorators that mimic function annotations in 3.x. For example:

@overload_with_some_decorator_for_generic_functions
@annotate(string_types, integer_types)
def func(arg1, arg2): pass

>>> func.__annotations__
{'arg1': basestring, 'arg2': (int, long)}

@annotate(some_kwarg='hola!')
@returns('greetings from the planet earth')
def func(a, b, c, some_kwarg): pass

>>> func.__annotations__
{'some_kwarg': 'hola!', 'return': 'greetings from the planet earth'}

The Python 3 versions would be:

@overload_with_some_decorator_for_generic_functions
def func(arg1: str, arg2: int): pass

def func(a, b, c, some_kwarg: 'hola!') -> 'greetings from the planet earth': pass

Revision history for this message
Benjamin Peterson (benjaminp) wrote :

six is about provide wrappers around things that changed from 2->3, not backporting 3.x features. It seems like this would be easy to include in any project needing it.

Changed in python-six:
importance: Undecided → Wishlist
Changed in python-six:
status: New → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.