[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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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/

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-id...@python.org/

https://www.python.org/dev/peps/

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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 profile != None:
... print(f"user: {profile['name']}")
... #
... 
... # new:
... if users.get(uid, None) as profile != None:
... print(f"user: {profile['name']}")
... #
...

--
components: Interpreter Core
messages: 385178
nosy: jen.soft.master
priority: normal
severity: normal
status: open
title: new "if-as" syntax
type: enhancement
versions: Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com