This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: new "if-as" syntax
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.10
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: jen.soft.master, steven.daprano
Priority: normal Keywords:

Created on 2021-01-18 09:59 by jen.soft.master, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg385178 - (view) Author: Евгений Jen (jen.soft.master) Date: 2021-01-18 09:59
# 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 profile != None:
...     print(f"user: {profile['name']}")
... #
... 
... # new:
... if users.get(uid, None) as profile != None:
...     print(f"user: {profile['name']}")
... #
...
msg385179 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-01-18 10:05
Use the walrus operator:

    if profile := users.get(uid, None) is not None:
        print(f"user: {profile['name']}")
msg385182 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-01-18 10:18
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/

https://docs.python.org/3/reference/expressions.html#assignment-expressions


I don't want to discourage you, but the process to get new syntax added to the library is:

* discuss it on Python-Ideas mailing list, to see if there is community support for it;

* if there is community support, as for a core developer to sponsor the idea;

* if you get a sponsor, write a PEP

* hopefully the Steering Council will accept it;

* and somebody (perhaps you, perhaps somebody else) will make the changes to the language.


https://mail.python.org/archives/list/python-ideas@python.org/

https://www.python.org/dev/peps/
msg385183 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-01-18 10:19
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**.
History
Date User Action Args
2022-04-11 14:59:40adminsetgithub: 87120
2021-01-18 10:19:59steven.dapranosetmessages: + msg385183
2021-01-18 10:18:40steven.dapranosetmessages: + msg385182
2021-01-18 10:05:45steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg385179

resolution: rejected
stage: resolved
2021-01-18 09:59:35jen.soft.mastercreate