syntax difference (type hints)

Schachner, Joseph Joseph.Schachner at Teledyne.com
Mon Jun 18 10:57:30 EDT 2018


Assuming that we want Python to remain a dynamically typed (but strongly typed) language, I believe the proposed type hints are only necessary for function definitions, where the caller really needs to know the types of arguments to pass in.   At the moment that purpose is (I think adequately) served by def strings, triple quoted strings immediately following the function declaration.  When I do code reviews for Python developed here, if the argument names of a function do not hint at the type they should be and there is no def string then I insist that something be added.  Often what gets added is a def string that says something about what the function does and explains what argument types are expected.

-- Joseph S.

-----Original Message-----
From: Ed Kellett <e+python-list at kellett.im> 
Sent: Monday, June 18, 2018 8:47 AM
To: python-list at python.org
Subject: Re: syntax difference

On 2018-06-18 13:18, Chris Angelico wrote:
> 1) Parse the code, keeping all the non-essential parts as well as the 
> essential parts.
> 2) Find the comments, or find the annotations
> 3) If comments, figure out if they're the ones you want to remove.
> 4) Reconstruct the file without the bits you want to remember.
> 
> Step 3 is removed if you're using syntactic annotations. Otherwise, 
> they're identical.

It's likely that Python comments are much easier to remove than arbitrary bits of Python syntax--you need to know the answer to "am I in a string literal?", which is a lexical analysis problem you could hack together a solution for over the course of about one coffee, as opposed to "where exactly am I in the Python parse tree?", which is... harder.
The information you need to keep track of and later reconstruct is substantially simpler, too.

I don't think "they're hard to mechanically remove" is a particularly good argument against type hints, but considered on its own it probably is true.



More information about the Python-list mailing list