> On Apr 26, 2018, at 11:00 AM, Fatty Morgan <fam...@gmail.com> wrote: > > I would like to urge you to reconsider the use of the token ':=' > for assignment expressions. > > 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)'.
PEP 484 type checkers *always* infer the type of an assignment based on the right-hand side's value. The main reason we require PEP 526 annotations at all is when your initial assignment is not useful for this inference. The two most common examples of this are `None` and empty containers. In those cases the type checker is unable to infer what the *intended* value should be, so it urges the programmer to explicitly state it. In this sense, `a := []` or `a := None` doesn't provide any additional information. And `a = 1` is already enough to determine what the expected type is. > The following should probably be discussed in python-ideas and > would only be relevant for a more distant future, but while I > have your attention, here are a couple of thoughts: Discussing this here will add to noise for Chris and the BDFL. Consider re-posting in python-ideas. -- Ł _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com