[Python-ideas] Re: dict.sort()?

2021-05-29 Thread Inada Naoki
FWI, this is a previous thread. https://discuss.python.org/t/add-a-dict-sort-method/5747 2021年5月30日(日) 1:57 Marco Sulla : > Since `dict` now is ordered, how about a `sort()` method? > It could have the same signature of list.sort(), with an optional > parameter "by" that can be "keys" or "values

[Python-ideas] Re: dict.sort()?

2021-05-29 Thread Steven D'Aprano
On Sat, May 29, 2021 at 06:54:15PM +0200, Marco Sulla wrote: > Since `dict` now is ordered, how about a `sort()` method? > It could have the same signature of list.sort(), with an optional > parameter "by" that can be "keys" or "values" ("keys" could be the > default). Dicts keep their insertion

[Python-ideas] Re: Cleaner tracebacks from Python code

2021-05-29 Thread Paul Sokolovsky
Hello, On Sat, 29 May 2021 17:29:26 -0300 André Roberge wrote: > On Sat, May 29, 2021 at 4:54 PM Irit Katriel > wrote: > > > > > You can control what the traceback of exceptions you are emitting: > > > > "raise e.with_traceback(None)" should clear everything before the > > current frame. > >

[Python-ideas] Re: Cleaner tracebacks from Python code

2021-05-29 Thread André Roberge
On Sat, May 29, 2021 at 4:54 PM Irit Katriel wrote: > > You can control what the traceback of exceptions you are emitting: > > "raise e.with_traceback(None)" should clear everything before the current > frame. > I'm sorry, but I still don't see how. This particular line would still show up. Tr

[Python-ideas] Re: Cleaner tracebacks from Python code

2021-05-29 Thread Irit Katriel via Python-ideas
You can control what the traceback of exceptions you are emitting: "raise e.with_traceback(None)" should clear everything before the current frame. Or you can get clever and construct a traceback with only the frames you want. On Saturday, May 29, 2021, 08:27:18 PM GMT+1, André Roberge w

[Python-ideas] Re: Cleaner tracebacks from Python code

2021-05-29 Thread Thomas Grainger
https://github.com/agronholm/anyio/blob/9eb4671547b01f5e3ba0e0ca602b6aceec15af86/src/anyio/_backends/_asyncio.py#L598 On Sat, 29 May 2021, 20:24 André Roberge, wrote: > > > On Sat, May 29, 2021 at 3:25 PM Thomas Grainger wrote: > >> pytest uses __tracebackhide__ >> >> https://doc.pytest.org/en

[Python-ideas] Re: Cleaner tracebacks from Python code

2021-05-29 Thread André Roberge
On Sat, May 29, 2021 at 3:25 PM Thomas Grainger wrote: > pytest uses __tracebackhide__ > > https://doc.pytest.org/en/latest/example/simple.html#writing-well-integrated-assertion-helpers > Thanks for the reminder. Pytest takes care of traceback formatting for users. Individual projects can of

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

2021-05-29 Thread Rob Cliffe via Python-ideas
On 29/05/2021 01:26, micro codery wrote: On Fri, May 28, 2021 at 5:07 PM Rob Cliffe Comailto:rob.cli...@btinternet.com>> wrote: On 29/05/2021 00:51, micro codery wrote: I also don't know what should happen for complicated assignments, and I think this has been the death

[Python-ideas] Re: Cleaner tracebacks from Python code

2021-05-29 Thread André Roberge
On Sat, May 29, 2021 at 3:38 PM Irit Katriel wrote: > See this issue: https://bugs.python.org/issue31299 > > This issue refers to https://bugs.python.org/issue16217 which talks about lines "above" the one of interest (compared with those that I describe as being "below"). It also talks about fi

[Python-ideas] Re: Cleaner tracebacks from Python code

2021-05-29 Thread Irit Katriel via Python-ideas
See this issue:  https://bugs.python.org/issue31299 On Saturday, May 29, 2021, 07:19:32 PM GMT+1, André Roberge wrote: With CPython, tracebacks obtained from code written in C can be extremely clean compared with functionally equivalent code written in Python.  Consider the followin

[Python-ideas] Re: Cleaner tracebacks from Python code

2021-05-29 Thread Thomas Grainger
pytest uses __tracebackhide__ https://doc.pytest.org/en/latest/example/simple.html#writing-well-integrated-assertion-helpers Eg anyio sets __tracebackhide__ = __traceback_hide__ = True to remove internal frames from user Tracebacks On Sat, 29 May 2021, 19:21 André Roberge, wrote: > With CPyth

[Python-ideas] Cleaner tracebacks from Python code

2021-05-29 Thread André Roberge
With CPython, tracebacks obtained from code written in C can be extremely clean compared with functionally equivalent code written in Python. Consider the following test file where I am using a local copy of Python's datetime.py module. ```py from local_datetime import date d = date(2021, 13, 1) `

[Python-ideas] Re: dict.sort()?

2021-05-29 Thread Jonathan Fine
On Sat, May 29, 2021 at 6:01 PM Chris Angelico > But if you're okay with constructing a new dict, you can do this: > > d = dict(sorted(d.items(), key=lambda kv: ...)) > Or to keep the same dict (not tested) tmp = list(sorted(d.items())) d.clear() d.update(tmp) -- Jonathan _

[Python-ideas] Re: dict.sort()?

2021-05-29 Thread Chris Angelico
On Sun, May 30, 2021 at 2:57 AM Marco Sulla wrote: > > Since `dict` now is ordered, how about a `sort()` method? > It could have the same signature of list.sort(), with an optional > parameter "by" that can be "keys" or "values" ("keys" could be the > default). Not really a thing - if you want th

[Python-ideas] dict.sort()?

2021-05-29 Thread Marco Sulla
Since `dict` now is ordered, how about a `sort()` method? It could have the same signature of list.sort(), with an optional parameter "by" that can be "keys" or "values" ("keys" could be the default). ___ Python-ideas mailing list -- python-ideas@python.o

[Python-ideas] SEMANTICS for 'variables' produced by a decorator

2021-05-29 Thread Jonathan Fine
There's been a discussion in this list on extending Python to provide SYNTAX such as @decorator name = EXPRESSION and also suitable semantics. (Here 'name' is an identifier, in the discussion called a 'variable'.) This post is about providing SEMANTICS for such decorator syntax. We can do

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

2021-05-29 Thread Matt del Valle
> > I just thought it looked better, but would you and others here like it > better if the > NEWLINE requirement was kept for all decorators? There is nothing in the > original > proposal that requires a single line. > I also don't know what should happen for complicated assignments, and I > think

[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-29 Thread Shreyan Avigyan
Now it seems Python doesn’t need constant. There are many ways we can achieve constants. Though constants may increase performance. Yet again it can also be the opposite. From: Paul Sokolovsky Sent: Saturday, May 29, 2021 12:44:09 AM To: Shreyan Avigyan Cc: pyt

[Python-ideas] Re: Add static variable storage in functions

2021-05-29 Thread Steven D'Aprano
On Fri, May 28, 2021 at 07:37:57PM -0700, Brendan Barnwell wrote: > I see your point, but I don't agree that static function variables > are parallel to either closures or generators. Okay, this is an important point, I think. I argue that some sort of sugar for static storage in fu