syntax difference (type hints)

Ian Kelly ian.g.kelly at gmail.com
Mon Jun 18 11:48:22 EDT 2018


FYI, Python type hints aren't "proposed"; they're already here. The
function annotation syntax was added in 3.0, without any imposition of
semantic meaning or requirements on it, and allowed to simmer for
several years for third-party frameworks to find uses for. Python 3.5
added the typing module to support type hinting in the style of Mypy
without any further language changes. Most recently, Python 3.6 added
syntax for annotating variables in addition to functions. All of these
things are already fully available in modern Python.
On Mon, Jun 18, 2018 at 9:05 AM Schachner, Joseph
<Joseph.Schachner at teledyne.com> wrote:
>
> 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.
>
> --
> https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list