[Python-ideas] Re: Add "try: stmt except: stmt" syntax to Python

2021-06-01 Thread Shreyan Avigyan
Reply to Chris: Yes you're right, I meant if-else expression. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message a

[Python-ideas] Re: The Pattern Matching Wildcard Is A Bad Idea

2021-06-01 Thread Steven D'Aprano
Hi Julia, and welcome! On Wed, Jun 02, 2021 at 05:16:29AM +0200, Julia Schmidt wrote: > The wildcard idea looks just wrong and confusing. What if I want to use it > as a variable and match against it like _ = 504? Don't do that. There is a very strong convention in Python that a single undersco

[Python-ideas] The Pattern Matching Wildcard Is A Bad Idea

2021-06-01 Thread Julia Schmidt
>From https://docs.python.org/3.10/whatsnew/3.10.html: def http_error(status): match status: case 400: return "Bad request" case 404: return "Not found" case 418: return "I'm a teapot" case _: return "Something's w

[Python-ideas] Re: Add "try: stmt except: stmt" syntax to Python

2021-06-01 Thread Chris Angelico
On Wed, Jun 2, 2021 at 10:59 AM Steven D'Aprano wrote: > > On Wed, Jun 02, 2021 at 10:47:46AM +1000, Chris Angelico wrote: > > > I can understand the confusion though, given that the parallel > > constructs cited for justification are all expressions. > > "conditional statement, list comprehension

[Python-ideas] Re: Add "try: stmt except: stmt" syntax to Python

2021-06-01 Thread Steven D'Aprano
On Wed, Jun 02, 2021 at 10:47:46AM +1000, Chris Angelico wrote: > I can understand the confusion though, given that the parallel > constructs cited for justification are all expressions. "conditional statement, list comprehensions, dict comprehensions" Two out of three is not bad. Conditional st

[Python-ideas] Re: Add "try: stmt except: stmt" syntax to Python

2021-06-01 Thread Steven D'Aprano
Why do you want this? Is there a shortage of newlines in your country? Maybe the Enter key is broken on your keyboard? *wink* Writing a proposal without a motivation is not very likely to get very far. "Put the code on one line" is not an acceptable motivation; *why* do you want to put it on o

[Python-ideas] Re: Add "try: stmt except: stmt" syntax to Python

2021-06-01 Thread Chris Angelico
On Wed, Jun 2, 2021 at 10:40 AM Steven D'Aprano wrote: > > On Tue, Jun 01, 2021 at 04:30:25PM -0400, Steele Farnsworth wrote: > > > This was proposed in 2014 and was rejected: > > https://www.python.org/dev/peps/pep-0463/ > > No, that's a proposal for a Python *expression* that can be imbedded in

[Python-ideas] Re: Add "try: stmt except: stmt" syntax to Python

2021-06-01 Thread Steven D'Aprano
On Tue, Jun 01, 2021 at 04:30:25PM -0400, Steele Farnsworth wrote: > This was proposed in 2014 and was rejected: > https://www.python.org/dev/peps/pep-0463/ No, that's a proposal for a Python *expression* that can be imbedded in another expression. Shreyan's proposal here is just to allow fitti

[Python-ideas] Re: A __decoration_call__ method for Callable objects (WAS: Decorators on variables)

2021-06-01 Thread Steven D'Aprano
On Tue, Jun 01, 2021 at 10:17:32PM +1000, Chris Angelico wrote: > My understanding is that it would attempt to invoke > __detonation_call__ (err, I mean, __decoration_call__, but just think > how awesome the other would be) first, and if it can't find it, it > falls back on regular __call__. That

[Python-ideas] Re: Add "try: stmt except: stmt" syntax to Python

2021-06-01 Thread Steele Farnsworth
This was proposed in 2014 and was rejected: https://www.python.org/dev/peps/pep-0463/ That being said, I would support such a thing being added to the language. My preferred syntax would be `try expression except ExceptionType [as e] with alternative`, or even `expression except ExceptionType [as

[Python-ideas] Add "try: stmt except: stmt" syntax to Python

2021-06-01 Thread Shreyan Avigyan
Python has support for conditional statement, list comprehensions, dict comprehensions, etc. So we can write these in mere one or two lines. But for try-except it's not possible to write it one or two lines. Many a times, we have one stmt that we want to check and if it raises error then do noth

[Python-ideas] Re: The name Ellipsis should be a constant

2021-06-01 Thread Christopher Barker
One other note that I'm surprised hasn't been brought up: In another thread, there is a discussion about what to use as sentinel objects -- often to indicate non-specified parameters, when None is a valid value. A number of people have proposed using the ellipses as such a value, as it already ex

[Python-ideas] Re: A __decoration_call__ method for Callable objects (WAS: Decorators on variables)

2021-06-01 Thread Paul Moore
On Tue, 1 Jun 2021 at 13:16, Steven D'Aprano wrote: > We can distinguish the two contexts by using different signatures. The > signature used depends entirely on the call site, not the decorator, so > it is easy for the interpreter to deal with. > > If the decorator is called on a function or cla

[Python-ideas] channel or message queue in asyncio

2021-06-01 Thread zhongquan789
Functionalities are similar to Go channel but with topics or consumers like a message queue. Possible syntax: ```python async def main(): ch = Channel() await ch.put(1) # put await ch.get() # get await ch.close()

[Python-ideas] Re: A __decoration_call__ method for Callable objects (WAS: Decorators on variables)

2021-06-01 Thread Chris Angelico
On Tue, Jun 1, 2021 at 10:16 PM Steven D'Aprano wrote: > The only slightly awkward case is the bare variable case. Most of the > time there will be no overlap between the function/class decorators and > the bare variable decorator, but in the rare case that we need to use a > single function in bo

[Python-ideas] Re: A __decoration_call__ method for Callable objects (WAS: Decorators on variables)

2021-06-01 Thread Chris Angelico
On Tue, Jun 1, 2021 at 9:57 PM Steven D'Aprano wrote: > > On Thu, May 27, 2021 at 12:33:20PM -0400, Ricky Teachey wrote: > > > On Thu, May 27, 2021 at 10:25 AM Steven D'Aprano > > wrote: > > > > > > Okay. Without reading the source code, does this code snippet use the > > > old `__call__` protoco

[Python-ideas] Re: A __decoration_call__ method for Callable objects (WAS: Decorators on variables)

2021-06-01 Thread Steven D'Aprano
Another problem I have with this proposal is the new dunder method. Why do we need a new dunder? We're probably never going to "decorate" a variable and function with the same callable, the two use-cases are very different. But even if we do, we can easily distinguish the two cases. Let's dump

[Python-ideas] Re: A __decoration_call__ method for Callable objects (WAS: Decorators on variables)

2021-06-01 Thread Steven D'Aprano
On Thu, May 27, 2021 at 12:33:20PM -0400, Ricky Teachey wrote: > On Thu, May 27, 2021 at 10:25 AM Steven D'Aprano > wrote: > > > > Okay. Without reading the source code, does this code snippet use the > > old `__call__` protocol or the new `__decoration_call__` protocol? > > > > > > @flambé >

[Python-ideas] Re: The name Ellipsis should be a constant

2021-06-01 Thread Steven D'Aprano
On Tue, Jun 01, 2021 at 08:28:56PM +1000, Steven D'Aprano wrote: > One easy change would be to just drop the capital E and call it > "ellipsis" (without the quotes), or even "the ellipsis symbol". To my > mind, that makes it clear we're talking about the symbol, not the > builtin name. https:/

[Python-ideas] Re: symbolic math in Python

2021-06-01 Thread Neil Girdhar
Oh, and I see you're a sympy developer! I hope I'm not coming across as critical in any way. I love that sympy exists and thought it was a really cool project when I first learned about what it can do. Perhaps we should move our discussion to a "Github discussion" under the sympy Github? We mig

[Python-ideas] Re: The name Ellipsis should be a constant

2021-06-01 Thread Jonathan Fine
We have the following. >>> 12 = True SyntaxError: can't assign to literal >>> True = False SyntaxError: can't assign to keyword >>> ... = False SyntaxError: can't assign to Ellipsis We also have (works better in monospaced font) >>> d[] = True d[] = True

[Python-ideas] Re: symbolic math in Python

2021-06-01 Thread Neil Girdhar
On Tue, Jun 1, 2021 at 6:28 AM Oscar Benjamin wrote: > > On Tue, 1 Jun 2021 at 10:53, Neil Girdhar wrote: > > > > On Tue, Jun 1, 2021 at 5:39 AM Oscar Benjamin > > wrote: > > > > > > On Tue, 1 Jun 2021 at 05:16, Neil Girdhar wrote: > > > > > > > > Hi Oscar, > > > > > > > > The problem that the

[Python-ideas] Re: symbolic math in Python

2021-06-01 Thread Oscar Benjamin
On Tue, 1 Jun 2021 at 10:53, Neil Girdhar wrote: > > On Tue, Jun 1, 2021 at 5:39 AM Oscar Benjamin > wrote: > > > > On Tue, 1 Jun 2021 at 05:16, Neil Girdhar wrote: > > > > > > Hi Oscar, > > > > > > The problem that the original poster was trying to address with > > > additional syntax is the au

[Python-ideas] Re: The name Ellipsis should be a constant

2021-06-01 Thread Steven D'Aprano
On Tue, Jun 01, 2021 at 05:48:34AM -0300, André Roberge wrote: > Actually, the very first observation I made is that, if you try to assign a > value to '...', the traceback includes the message: > > SyntaxError: cannot assign to Ellipsis > > which is clearly wrong. It is not _clearly_ wrong. El

[Python-ideas] Re: symbolic math in Python

2021-06-01 Thread Neil Girdhar
On Tue, Jun 1, 2021 at 5:39 AM Oscar Benjamin wrote: > > On Tue, 1 Jun 2021 at 05:16, Neil Girdhar wrote: > > > > Hi Oscar, > > > > The problem that the original poster was trying to address with > > additional syntax is the automatic naming of symbols. He wants to > > omit this line: > > > > x

[Python-ideas] Re: symbolic math in Python

2021-06-01 Thread Oscar Benjamin
On Tue, 1 Jun 2021 at 05:16, Neil Girdhar wrote: > > Hi Oscar, > > The problem that the original poster was trying to address with > additional syntax is the automatic naming of symbols. He wants to > omit this line: > > x = symbols("x") > > You're right that if you have many one-character symbol

[Python-ideas] Re: The name Ellipsis should be a constant

2021-06-01 Thread Serhiy Storchaka
31.05.21 22:24, André Roberge пише: > > > On Mon, May 31, 2021 at 4:17 PM Serhiy Storchaka > > wrote: > 31.05.21 17:37, André Roberge пише: > > For consistency, `Ellipsis` (the name) should **always** refer to the > > same object that `...` refers to, so t

[Python-ideas] Re: The name Ellipsis should be a constant

2021-06-01 Thread André Roberge
On Tue, Jun 1, 2021 at 1:46 AM David Mertz wrote: > On Mon, May 31, 2021 at 11:41 PM Steven D'Aprano > wrote: > >> >> > >> Not every builtin needs a mollyguard to protect against misuse. >> > > I'm not likely to rebind `Ellipsis` so that's not really my concern. > Rather, I'm interested in the p