[Python-Dev] Reserve ':=' for type-inferred variable initialization (was PEP 572) (original) (raw)
Andrea Griffini agriff at tin.it
Fri Apr 27 02:13:20 EDT 2018
- Previous message (by thread): [Python-Dev] Reserve ':=' for type-inferred variable initialization (was PEP 572)
- Next message (by thread): [Python-Dev] Reserve ':=' for type-inferred variable initialization (was PEP 572)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
We're focused on Python 3.8 and 3.9, not Python 5 or Python 6.
Hmmm... When I was hearing the repeated belated saying that Python will never ever jump on the statically typed ship on each and every static type annotation discussion I started to worry this wasn't indeed the case (why the urge of repeating it so much otherwise?).
Now we got standard library features requiring type annotation and a little shift towards a "not now" position.
I'm just wondering... I'm NOT saying this would be bad (or good).
On Fri, Apr 27, 2018 at 2:36 AM, Steven D'Aprano <steve at pearwood.info> wrote:
Hi Fatty, and welcome!
On Thu, Apr 26, 2018 at 08:00:55PM +0200, Fatty Morgan wrote: > The natural interpretation of 'name := expr' is a PEP 526 > type-annotated variable initialization 'name : T = expr' with the > type annotation T omitted, the tokens ':' and '=' coalesced, and > the implied type T inferred as 'type(expr)'. I'm not sure why you say that is the "natural" interpretation, unless you're saying that Guido, Chris, myself and dozens of other people taking part of this conversation are unnatural, since none of us thought of that interpretation smiles The := token is the second most common assignment operator in programming languages, behind only = single equals sign. For those of us who were raised on Pascal, it is entirely natural to use = for equality tests and := for assignment, and languages that use == for equality are the ones which are weird. Since type-annotations are still only used by a small proportion of Python code and Python developers, I doubt that they will jump to the interpretation of "explicit type hint with no type given". If the type-checker can infer the type of the expression, there's no need to use the colon at all. name := expression # can infer type here name = expression # why not just infer the type here? So using : Type without the type is entirely unnecessary. The colon is only needed when you have to specify a type manually. Your comments about some entirely hypothetical "Python with enforced static typing" are interesting but so blue-sky that I honestly doubt that there's any point in discussing them now. We're focused on Python 3.8 and 3.9, not Python 5 or Python 6.
-- Steve
Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/ agriff%40tin.it -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180427/e0a7f5af/attachment.html>
- Previous message (by thread): [Python-Dev] Reserve ':=' for type-inferred variable initialization (was PEP 572)
- Next message (by thread): [Python-Dev] Reserve ':=' for type-inferred variable initialization (was PEP 572)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]