Python Sanity Proposal: Type Hinting Solution

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat Jan 24 12:26:39 EST 2015


Rick Johnson wrote:

> On Saturday, January 24, 2015 at 7:30:02 AM UTC-6, Steven D'Aprano wrote:
>> [...] It requires extra complexity to the parser, so that
>> decorators may be separated from the function by a hint:
>> 
>> @decorate
>> "@typehint: (str, int) -> bool"
>> def myfunction(arg1, arg2):
>> 
>> No doubt some people will get them the wrong way around,
>> and the type checker may silently ignore their hints:
>> 
>> "@typehint: (str, int) -> bool"
>> @decorate
>> def myfunction(arg1, arg2):
>> 
>> And others will write:
>> 
>> @decorate
>> @typehint(str, int) -> bool
>> def myfunction(arg1, arg2):
>> 
>> 
>> and be annoyed or perplexed by the syntax error.
>> 
>> Some syntax will be a bug magnet. This is one.
> 
> Your argument is weak here. If the interpreter cannot
> distinguish between "@typehint ..." and "@ ..." 

Thank you for demonstrating my point for me.

The difference is not

@typehint(...)
def func(...): 

versus any other decorator, but the STRING:

"@typehint(...)"

being used where a decorator would normally be expected.

If a genius of the degree like Rick can be fooled, what hope do ordinary
mortals have?



-- 
Steven




More information about the Python-list mailing list