[Python-ideas] Optional static typing -- the crossroads

Chris Angelico rosuav at gmail.com
Mon Aug 18 03:11:23 CEST 2014


On Mon, Aug 18, 2014 at 9:43 AM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Chris Angelico wrote:
>>
>> I don't, for instance, see
>> real-world examples of decorators that add extra parameters to a
>> function, even though it would be plausible
>
>
> Some decorators, such as property(), don't return a
> function at all. Ignoring the decorator in that case
> would give completely the wrong idea.

So you don't annotate the function that handles the property. Simple!

There may need to be some other handling of it (telling mypy that this
property will always be a str, for instance), but the function's
arguments aren't significant to the type system, so they don't need
annotations. Same is true of anything else that decorates the function
away altogether.

ChrisA


More information about the Python-ideas mailing list