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

Nick Coghlan ncoghlan at gmail.com
Fri Aug 15 11:48:10 CEST 2014


On 15 August 2014 19:38, Terry Reedy <tjreedy at udel.edu> wrote:
> On 8/15/2014 12:40 AM, Nick Coghlan wrote:
>>
>> On 15 August 2014 09:56, Guido van Rossum <guido at python.org> wrote:
>>>
>>>
>>> I don't buy the argument that PEP 3107 promises that annotations are
>>> completely free of inherent semantics.
>>
>>
>> It's also worth noting the corresponding bullet point in PEP 3100
>> (under http://www.python.org/dev/peps/pep-3100/#core-language):
>>
>> * Add optional declarations for static typing [45] [10] [done]
>
> ...
>
>> Linters/checkers may also want to provide a configurable way to say
>> "the presence of decorator <X> means the annotations on that function
>> aren't type markers". That ties in with the recommendation we added to
>> PEP 8 a while back: "It is recommended that third party experiments
>> with annotations use an associated decorator to indicate how the
>> annotation should be interpreted."
>
>
> Depending on the checker, this suggests that non-type-check annotations need
> not be deprecated. If a decorator wraps a function with an unannotated
> wrapper, then the checker should see the result as unannotated, rather than
> looking for a wrapped attribute. Also, a decorator can remove non-type
> annotations and act on them, store them in a closure variable, or store them
> on the function in a different name.

No, many (most?) linters and IDEs will run off the AST without
actually executing the code, so they'll see the annotations, even if
they get stripped by the decorator at runtime.

Cheers,
Nick.


-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list