[issue42954] new "if-as" syntax

2021-01-18 Thread Steven D'Aprano
Steven D'Aprano added the comment: I'm not having a good day :-( > the process to get new syntax added to the library The process to get new syntax added to the **language**. -- ___ Python tracker

[issue42954] new "if-as" syntax

2021-01-18 Thread Steven D'Aprano
Steven D'Aprano added the comment: Oops sorry I got the operator precedence wrong: if (profile := users.get(uid, None)) is not None: The walrus operator was added in Python 3.8. Using the "as" key word was considered and rejected. See the PEP: https://www.python.org/dev/peps/pep-0572/

[issue42954] new "if-as" syntax

2021-01-18 Thread Steven D'Aprano
Steven D'Aprano added the comment: Use the walrus operator: if profile := users.get(uid, None) is not None: print(f"user: {profile['name']}") -- nosy: +steven.daprano resolution: -> rejected stage: -> resolved status: open -> closed _

[issue42954] new "if-as" syntax

2021-01-18 Thread Евгений Jen
New submission from Евгений Jen : # use if users.get(uid, None) as profile != None: ... # instead profile = users.get(uid, None) if profile != None: ... # full-sample: >>> users = {1: {"name": "Jen"}} ... uid = 1 ... ... # current syntax: ... profile = users.get(uid, None) ... if pro