[Python-ideas] Suggestion for standardized annotations

CFK cfkaran2 at gmail.com
Wed Mar 5 20:24:57 CET 2014


On Wed, Mar 5, 2014 at 8:45 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> On 5 Mar 2014 22:51, "Paul Moore" <p.f.moore at gmail.com> wrote:
> >
> > On 5 March 2014 11:53, Cem Karan <cfkaran2 at gmail.com> wrote:
> > > Thoughts/suggestions?
> >
> > I think the core/stdlib position is that agreeing conventions would be
> > better done once some real world experience of the practical issues
> > and benefits of annotations has been established.
>
> MyPy uses function annotations for optional static typing, which is pretty
> much the use case Guido originally had in mind and the main reason that PEP
> 8 doesn't make combining annotations with an associated decorator
> mandatory: http://www.mypy-lang.org/
>
> You do still have to import a particular module to indicate that all
> annotations in the importing module are to be interpreted as type
> annotations.
>
> Beyond that, the guidance in PEP 8 stands:
>
> """It is recommended that third party experiments with annotations use an
> associated decorator to indicate how the annotation should be
> interpreted."""
>
I like what all of you are suggesting; decorators are the way to go.  If a
project defines its own annotation decorators as
sigtools.modifiers.annotate<http://sigtools.readthedocs.org/en/latest/_modules/sigtools/modifiers.html#annotate>,
mypy, <http://www.mypy-lang.org/> or
pyanno<http://www.fightingquaker.com/pyanno>do, then it shouldn't be
too hard for a project to add its own UUID to the
annotation dictionary.  I'll spend a little while this weekend seeing if I
can come up with some proof-of-concept code to make this work in a portable
way.  If the signatures looked vaguely like the following:

@type_annotation(some_arg, int)
@return_type_annotation(int)
def function(some_arg):
    pass

Would that be appealing to everyone?

One question though, are we allowed to modify a functions __annotation__
dictionary directly?  I know that I can do it, I just don't know if it is
discouraged.

Thanks,
Cem Karan
<http://www.fightingquaker.com/pyanno>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140305/f8031bdd/attachment.html>


More information about the Python-ideas mailing list