Python Sanity Proposal: Type Hinting Solution
marfig at gmail.com
Sat Jan 24 00:14:31 CET 2015
In article <c1d9c448-31b0-4bbc-8c6f-5194678a6f87 at googlegroups.com>,
sohcahtoa82 at gmail.com says...
> > def myfunction(arg1, arg2):
> > """
> > Normal docstring...
> > @typehint: (str, int) -> bool
> > """
> > return True
> I really like that implementation.
> Its unobtrusive and doesn't clutter the function definition, and
> putting in the docstring makes it get colored like a comment (At
> least, with my IDE setup it does) so it is easily ignored by my eyes
> as I'm scrolling through.
It has the side effect of being included in __doc__. A purist may have
an issue with that, since type hinting, for the purposes of static
analysis, should have no place in that attribute.
But you could always fall back to the previous version:
def myfunction(arg1, arg2):
"@typehint: (str, int) -> bool"
And __doc__ would be free of it. It would be up to the user to choose.
For something completely different, I like @hint: better than @typehint:
More information about the Python-list