syntax difference

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Jun 19 13:07:25 EDT 2018


On Mon, 18 Jun 2018 10:34:54 -0700, Jim Lee wrote:

> The syntax should be defined inside comments

Then you ought to be pleased that from Python 4.0 (or from Python 3.7 
with a ``__future__`` import) annotations will be treated as strings by 
the interpreter.

That makes them effectively special comments like docstrings: they aren't 
executed, only recorded in the object for introspection.

def func(x: int) -> str:

becomes precisely the same as:

def func(x): # type x:int, return:str

except that the comment is attached to the function as a string for 
runtime introspection.


> by the tools that actually
> need to use them.  Let the tools do what they were designed to do.  Let
> the language do what it was designed to do.

Then you should be glad, because the language is designed to do this. 
Annotations in Python are the end result of a long, carefully thought out 
design process.


> If static type checking were a high priority, I would not choose a
> language like Python for the task

You are talking as if "static type checking" were an end in itself. 
That's like saying "If unit tests were a high priority, I would not 
choose a language like C".

Static type-checking is a means to an end. The end is more reliable code 
and making it easier to find bugs. I trust you don't mean to imply that 
you don't need to find bugs in Python code.

If your linter or IDE can tell you that the function you intended to 
return a string can sometimes return None, why is this so horrible?


> - but some people seem to want to beat
> the language into submission as a do-everything-but-wash-my-car
> solution; and in so doing, the language becomes so fragile and bloated
> that people will walk away from it.

Ah, I wondered how long it would be before the "feature X is killing 
Python" FUD reared its ugly head.


> In reading through many of the PEPs, I'm reminded of the saying, "If all
> you have is a hammer, everything looks like a nail".

And when the most advanced tool you've used is a hammer, an electric 
drill looks like a very expensive, awkward to use hammer.



-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson




More information about the Python-list mailing list