[Python-Dev] Re: Having Sorted Containers in stdlib?

2021-11-09 Thread Serhiy Storchaka
10.11.21 01:47, Bob Fang пише: > 1) Some mainstream language support them out of box: C++ for example > have set/map which are sorted by the key order, and Java has TreeMap > which is internally a Red-black tree. >From my C++ and Java experience, hashtable-based containers are much more useful

[Python-Dev] Re: Having Sorted Containers in stdlib?

2021-11-09 Thread Paul Bryan
On Wed, 2021-11-10 at 17:16 +1100, Steven D'Aprano wrote: > On Tue, Nov 09, 2021 at 10:01:35PM -0800, Christopher Barker wrote: > > Maybe a stupid question: > > > > What are use cases for sorted dicts? > > > > I don’t think I’ve ever needed one. > > Good question :-) It could be handy for

[Python-Dev] Re: Having Sorted Containers in stdlib?

2021-11-09 Thread Chris Angelico
On Wed, Nov 10, 2021 at 5:45 PM Steven D'Aprano wrote: > > On Wed, Nov 10, 2021 at 05:11:33PM +1100, Chris Angelico wrote: > > > Nothing's technically new. You could make an inefficient sorted dict like > > this: > > > > class SortedDict(dict): > > def __iter__(self): return

[Python-Dev] Re: Having Sorted Containers in stdlib?

2021-11-09 Thread Steven D'Aprano
On Wed, Nov 10, 2021 at 05:11:33PM +1100, Chris Angelico wrote: > Nothing's technically new. You could make an inefficient sorted dict like > this: > > class SortedDict(dict): > def __iter__(self): return iter(sorted(self.keys())) You would need more than that. You would want to ensure

[Python-Dev] Re: Having Sorted Containers in stdlib?

2021-11-09 Thread Steven D'Aprano
On Tue, Nov 09, 2021 at 10:01:35PM -0800, Christopher Barker wrote: > Maybe a stupid question: > > What are use cases for sorted dicts? > > I don’t think I’ve ever needed one. Good question :-) > Also, I can’t quite tell from the discussion If a “sorted dict” implements > something new, or

[Python-Dev] Re: Having Sorted Containers in stdlib?

2021-11-09 Thread Chris Angelico
On Wed, Nov 10, 2021 at 5:03 PM Christopher Barker wrote: > > Maybe a stupid question: > > What are use cases for sorted dicts? > > I don’t think I’ve ever needed one. Me neither, tbh. > Also, I can’t quite tell from the discussion If a “sorted dict” implements > something new, or is an

[Python-Dev] Re: Having Sorted Containers in stdlib?

2021-11-09 Thread Hasan Diwan
A quick Google for "treap python github" yielded https://github.com/TheAlgorithms/Python/blob/master/data_structures/binary_tree/treap.py . On Tue, 9 Nov 2021 at 21:49, Dan Stromberg wrote: > > On Tue, Nov 9, 2021 at 9:00 PM Steven D'Aprano > wrote: > >> Sorting dicts has been discussed on the

[Python-Dev] Re: Having Sorted Containers in stdlib?

2021-11-09 Thread Christopher Barker
Maybe a stupid question: What are use cases for sorted dicts? I don’t think I’ve ever needed one. Also, I can’t quite tell from the discussion If a “sorted dict” implements something new, or is an internal data structure that gives better performance for particular use cases. I.e. is a sorted

[Python-Dev] Re: Having Sorted Containers in stdlib?

2021-11-09 Thread Dan Stromberg
On Tue, Nov 9, 2021 at 9:00 PM Steven D'Aprano wrote: > Sorting dicts has been discussed on the Python-Ideas mailing list, it is > too hard and expensive to justify for the limited use-cases for it. If > you want to sort a dict, you are best to sort the dict's keys, then > create a new dict. Or

[Python-Dev] Re: Having Sorted Containers in stdlib?

2021-11-09 Thread Steven D'Aprano
Hi Bob and welcome, Before we could even consider adding the sortedcontainers library to the standard library, we would need to hear from the maintainer(s) of the library that they agree to the move and would be able to continue maintaining the library under our release schedule and backwards

[Python-Dev] Re: Having Sorted Containers in stdlib?

2021-11-09 Thread Steven D'Aprano
On Tue, Nov 09, 2021 at 04:23:50PM -0800, Hasan Diwan wrote: > As of 3.7. dicts are sorted[1], but I'm unsure if the order can be > overridden. Dicts are not sorted, they are kept in insertion order. >>> d = {3: 'a', 4: 'b', 1: 'c', 2: 'd'} >>> d {3: 'a', 4: 'b', 1: 'c', 2: 'd'}

[Python-Dev] Re: Proposal: Allow non-default after default arguments

2021-11-09 Thread Richard Damon
On 11/9/21 3:24 PM, Terry Reedy wrote: On 11/9/2021 1:52 PM, Sebastian Rittau wrote: Am 09.11.21 um 19:26 schrieb Terry Reedy: The signature of Sebastian's function with honest parameter names is foo(x_or_y, required_y=_NotGiven, /).  It is the 2nd argument, not the first, that is optional,

[Python-Dev] Re: Having Sorted Containers in stdlib?

2021-11-09 Thread Hasan Diwan
On Tue, 9 Nov 2021, 17:05 Bob Fang, wrote: > But that’s in insertion order, not in key order right? I think we need > data structure that are key-ordered. > According to the tests, it seems to be key-ordered. It also appears that the ordering cannot be changed (yet?). -- H

[Python-Dev] Re: Having Sorted Containers in stdlib?

2021-11-09 Thread Bob Fang
But that’s in insertion order, not in key order right? I think we need data structure that are key-ordered. > On 10 Nov 2021, at 00:23, Hasan Diwan wrote: > > > On Tue, 9 Nov 2021 at 16:01, Bob Fang > wrote: > This is a modest proposal to consider having

[Python-Dev] Re: containment and the empty container

2021-11-09 Thread Chris Angelico
On Wed, Nov 10, 2021 at 11:44 AM Ethan Furman wrote: > I don't know if there's a formal name, but in my mind, if you have something > you don't have nothing. If you have a > barrel with nothing in it (not even air, just a hard vacuum) then saying you > have nothing in that barrel is a true >

[Python-Dev] Re: containment and the empty container

2021-11-09 Thread Ethan Furman
On 11/8/21 3:09 PM, Steven D'Aprano wrote: > On Mon, Nov 08, 2021 at 01:43:03PM -0800, Ethan Furman wrote: >> SomeFlag.nothing in SomeFlag.something <-- ??? > > I don't think that consistency with other containers is particularly > relevant here. More useful is consistency with other flag

[Python-Dev] Re: Having Sorted Containers in stdlib?

2021-11-09 Thread Hasan Diwan
On Tue, 9 Nov 2021 at 16:01, Bob Fang wrote: > This is a modest proposal to consider having sorted containers ( > http://www.grantjenks.com/docs/sortedcontainers/ >

[Python-Dev] Having Sorted Containers in stdlib?

2021-11-09 Thread Bob Fang
Hi All, This is a modest proposal to consider having sorted containers (http://www.grantjenks.com/docs/sortedcontainers/ ) in standard library. I know that usually adding stuff to standard library requires some strong arguments, so I will try

[Python-Dev] Re: Proposal: Allow non-default after default arguments

2021-11-09 Thread Guido van Rossum
On Tue, Nov 9, 2021 at 12:27 PM Terry Reedy wrote: > On 11/9/2021 1:52 PM, Sebastian Rittau wrote: > > Am 09.11.21 um 19:26 schrieb Terry Reedy: > >> The signature of Sebastian's function with honest parameter names is > >> foo(x_or_y, required_y=_NotGiven, /). It is the 2nd argument, not the >

[Python-Dev] Re: Proposal: Allow non-default after default arguments

2021-11-09 Thread Terry Reedy
On 11/9/2021 1:52 PM, Sebastian Rittau wrote: Am 09.11.21 um 19:26 schrieb Terry Reedy: The signature of Sebastian's function with honest parameter names is foo(x_or_y, required_y=_NotGiven, /).  It is the 2nd argument, not the first, that is optional, as with range.  If required_y is not

[Python-Dev] Re: Proposal: Allow non-default after default arguments

2021-11-09 Thread Sebastian Rittau
Am 09.11.21 um 19:26 schrieb Terry Reedy: The signature of Sebastian's function with honest parameter names is foo(x_or_y, required_y=_NotGiven, /).  It is the 2nd argument, not the first, that is optional, as with range.  If required_y is not given, than x_or_y must be y, and x is given a

[Python-Dev] Re: Typing :: Typed Classifier

2021-11-09 Thread Simon J.M. Kelley
Hey Rakshith, On Tue, Nov 9, 2021, at 6:49 PM, rakshith.bhyravabho...@gmail.com wrote: > Is it simply "the package has typing"? Or does it have a more > extensive implication? As far as I can tell it is simply the former. Regards, Simon ___

[Python-Dev] Re: Proposal: Allow non-default after default arguments

2021-11-09 Thread Terry Reedy
On 11/9/2021 9:23 AM, Steven D'Aprano wrote: By the way, this discussion is probably better suited to the Python-Ideas mailing list. But since we're here... On Tue, Nov 09, 2021 at 11:37:40AM +0100, Sebastian Rittau wrote: To me, the "natural" solution looks like this: def foo(x=None, y):

[Python-Dev] Re: NASA Inquiry

2021-11-09 Thread Simon J.M. Kelley
Hi Charita, On Tue, Nov 9, 2021, at 2:14 PM, Elmore, Charita R. (GSFC-705.0)[TELOPHASE CORP] via Python-Dev wrote: > REF: RITM1146898 > > Hello, my name is Charita Elmore and I am a Supply Chain Risk > Management Coordinator at NASA.  As such, I ensure that all NASA > acquisitions of Covered

[Python-Dev] Typing :: Typed Classifier

2021-11-09 Thread rakshith . bhyravabhotla
Hi, What are the implications of using a Typing :: typed classifier? Is it simply "the package has typing"? Or does it have a more extensive implication? ___ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to

[Python-Dev] NASA Inquiry

2021-11-09 Thread Elmore, Charita R. (GSFC-705.0)[TELOPHASE CORP] via Python-Dev
REF: RITM1146898 Hello, my name is Charita Elmore and I am a Supply Chain Risk Management Coordinator at NASA.  As such, I ensure that all NASA acquisitions of Covered Articles comply with Section 208 of the Further Consolidated Appropriations Act, 2020, Public Law 116-94, enacted December 20,

[Python-Dev] Re: Proposal: Allow non-default after default arguments

2021-11-09 Thread Brett Cannon
On Tue, Nov 9, 2021 at 6:31 AM Steven D'Aprano wrote: > By the way, this discussion is probably better suited to the > Python-Ideas mailing list. But since we're here... > > On Tue, Nov 09, 2021 at 11:37:40AM +0100, Sebastian Rittau wrote: > > > >>To me, the "natural" solution looks like this: >

[Python-Dev] Re: containment and the empty container

2021-11-09 Thread Guido van Rossum
On Mon, Nov 8, 2021 at 10:29 PM Ethan Furman wrote: > > The way I see it, the following should hold > > empty_flag = RegexFlag(0) > any_case = RegexFlag.IGNORECASE > any_case_on_any_line = RegexFlag.IGNORECASE | RegexFlag.MULTILINE > > any_case in empty_flag is False >

[Python-Dev] Ignore my previous post Re: containment and the empty container

2021-11-09 Thread Stephen J. Turnbull
Aargh. The whole point of Cameron's post was about implementing "in", and all of it makes sense now. Sorry. ___ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org

[Python-Dev] Re: containment and the empty container

2021-11-09 Thread Stephen J. Turnbull
Cameron Simpson writes: > On 08Nov2021 23:32, MRAB wrote: > >A flag could be a member, but could a set of flags? > > Probably one flavour should raise a TypeError then with this comparison. > I wouldn't want "member flag present in SomeFlag.something" and > "set-of-members present in

[Python-Dev] Re: Proposal: Allow non-default after default arguments

2021-11-09 Thread Sebastian Rittau
Am 09.11.21 um 13:44 schrieb Petr Viktorin: And for the "encoding" case: IMO, varying the return type based on an optional "encoding" argument" is a holdover from the pre-typing era, when return types were only specified in the documentation -- just like "addch" is a holdover from the days

[Python-Dev] Re: Proposal: Allow non-default after default arguments

2021-11-09 Thread Steven D'Aprano
By the way, this discussion is probably better suited to the Python-Ideas mailing list. But since we're here... On Tue, Nov 09, 2021 at 11:37:40AM +0100, Sebastian Rittau wrote: > >>To me, the "natural" solution looks like this: > >> > >>def foo(x=None, y): ... [...] Chris Angelico asked: >

[Python-Dev] Re: Proposal: Allow non-default after default arguments

2021-11-09 Thread Victor Stinner
IMO it was a bad idea to merge 2 ncurses C functions into a single Python function. In the C API, there are two different functions: * mvwadd_wch(win, y, x, char): 4 arguments * wadd_wch(win, char): 2 arguments The Python curses module could/can have a separated function when (y, x) arguments

[Python-Dev] Re: Proposal: Allow non-default after default arguments

2021-11-09 Thread Petr Viktorin
On 09. 11. 21 10:50, Chris Angelico wrote: On Tue, Nov 9, 2021 at 8:38 PM Sebastian Rittau wrote: Currently, Python doesn't allow non-default arguments after default arguments: >>> def foo(x=None, y): pass File "", line 1 def foo(x=None, y): pass ^

[Python-Dev] Re: PEP 467: Minor bytes and bytearray improvements

2021-11-09 Thread Victor Stinner
On Mon, Nov 8, 2021 at 8:21 PM Ethan Furman wrote: > The difference with the built-in ascii is the absence of extra quotes and the > `b` indicator when a string is used: > > ``` > >>> u_var = u'abc' > >>> bytes.ascii(u_var) > b'abc' What about bytes, bytearray and memoryview? What is the

[Python-Dev] Re: Proposal: Allow non-default after default arguments

2021-11-09 Thread Paul Moore
On Tue, 9 Nov 2021 at 10:39, Sebastian Rittau wrote: > This might be better API design (although I don't think Python should be > opinionated about this outside the standard library), but this still > leaves the API change example and the very real problem of @overloads > unsolved. You can

[Python-Dev] Re: Proposal: Allow non-default after default arguments

2021-11-09 Thread Sebastian Rittau
Am 09.11.21 um 10:50 schrieb Chris Angelico: On Tue, Nov 9, 2021 at 8:38 PM Sebastian Rittau wrote: Currently, Python doesn't allow non-default arguments after default arguments: >>> def foo(x=None, y): pass File "", line 1 def foo(x=None, y): pass ^

[Python-Dev] Re: containment and the empty container

2021-11-09 Thread Stephen J. Turnbull
Tim Peters writes: > [Ethan Furman ] > > .. on the other hand, it seems that collections of related flags > > are often treated as in set theory, where the empty set is a > > member of any non-empty set. > > Not how any set theory I've ever seen works: a set S contains the > empty set if

[Python-Dev] Re: Proposal: Allow non-default after default arguments

2021-11-09 Thread Chris Angelico
On Tue, Nov 9, 2021 at 8:38 PM Sebastian Rittau wrote: > > Currently, Python doesn't allow non-default arguments after default > arguments: > > >>> def foo(x=None, y): pass >File "", line 1 > def foo(x=None, y): pass > ^ > SyntaxError: non-default argument follows

[Python-Dev] Proposal: Allow non-default after default arguments

2021-11-09 Thread Sebastian Rittau
Currently, Python doesn't allow non-default arguments after default arguments: >>> def foo(x=None, y): pass   File "", line 1     def foo(x=None, y): pass ^ SyntaxError: non-default argument follows default argument I believe that at the time this was introduced, no use

[Python-Dev] Re: containment and the empty container

2021-11-09 Thread Greg Ewing
On 9/11/21 7:29 pm, Ethan Furman wrote: I've had a couple people tell me that they think of flags as sets, and use set theory / set behavior to understand how flags and groups of flags should interact. If you're going to think of flags as sets, then 'i in flags' should be equivalent to '((1

[Python-Dev] Re: containment and the empty container

2021-11-09 Thread Paul Moore
On Tue, 9 Nov 2021 at 06:31, Ethan Furman wrote: (IMO, Steven D'Aprano's comment above, which I don't think you have responded to yet, is the clearest summary of the options here. I agree with what he says, but just wanted to clarify one point below). > I've had a couple people tell me that