[Python-ideas] Re: dict_items.__getitem__?

2021-10-10 Thread Stephen J. Turnbull
Chris Angelico writes: > Using popitem mutates the underlying dict. That's a tad more likely > to affect other parts of the code. Granted. The context is opposition to itertools.first. "Advocating" popitem is tongue-in-cheek, with the serious point is that it's obvious that it alters state

[Python-ideas] socketserver StreamRequestHandler non-blocking read__

2021-10-10 Thread Evan Greenup via Python-ideas
For StreamRequetHandler's rfile attribute, it will block when the read readline readlines reach the end. It would be nice to add non-blocking read because the seek() is unavailable for rfile. and there is no other way to detect if it is ended. When the stream is empty and waiting for new

[Python-ideas] Re: dict_items.__getitem__?

2021-10-10 Thread Alex Waygood
> > here is the thread from the last time that this was brought up: > > https://mail.python.org/archives/list/python-ideas@python.org/thread/S7UMTWK65X6BJDYZ3SSU7I7HOIASDMMJ/#S7UMTWK65X6BJDYZ3SSU7I7HOIASDMMJ Thanks, that's very helpful. Sounds like Guido is right, and the short answer is "while

[Python-ideas] Re: Adding a Version type

2021-10-10 Thread Finn Mason
Thank you for the feedback. I was unaware of the packaging package and PEP 440. I recognize that there are definitely some problems with my idea. I took a look at the packaging package, and I think it might be a good idea to put something like it in the stdlib. The Version type there from what I

[Python-ideas] Re: dict_items.__getitem__?

2021-10-10 Thread Christopher Barker
here is the thread from the last time that this was brought up: https://mail.python.org/archives/list/python-ideas@python.org/thread/S7UMTWK65X6BJDYZ3SSU7I7HOIASDMMJ/#S7UMTWK65X6BJDYZ3SSU7I7HOIASDMMJ It was very thoroughly discussed then. -CHB On Sun, Oct 10, 2021 at 8:33 AM Guido van Rossum

[Python-ideas] Re: dict_items.__getitem__?

2021-10-10 Thread Guido van Rossum
You have to check the C code to be sure, but IIRC the latest dict implementation has a dense array of the values in insert order, and the hash table (which has gaps) contains indexes into the values array. So you could easily index into the values array (which I believe also has the keys) in O(1)

[Python-ideas] Re: dict_items.__getitem__?

2021-10-10 Thread Alex Waygood
> Should `dict.items()` be indexable now that dicts are ordered? I say yes. Why > shouldn't it? Would there be a way to ensure that this had the same time complexity as indexing of sequences? If "yes", I would support this — I think it would be useful in some situations, and it would be more

[Python-ideas] Re: dict_items.__getitem__?

2021-10-10 Thread Alex Waygood
> The problem is that first() does not return the first item of the > iterator, but the *next item still available*. > >a = list('12345') >b = iter('12345') > >first(a) == first(a) # True >first(b) == first(b) # False This is an excellent point, and something I hadn't

[Python-ideas] Re: dict_items.__getitem__?

2021-10-10 Thread Chris Angelico
On Mon, Oct 11, 2021 at 12:17 AM Stephen J. Turnbull wrote: > > Steven D'Aprano writes: > > On Sun, Oct 10, 2021 at 01:51:52AM +0900, Stephen J. Turnbull wrote: > > > Christopher Barker writes: > > > > > > > But last time, one of the use cases was "get [an arbitrary] item > > > > from a

[Python-ideas] Re: Adding a Version type

2021-10-10 Thread Steven D'Aprano
On Sat, Oct 09, 2021 at 08:16:58PM -0600, Finn Mason wrote: > I feel like there could be a better way to define versions. There's no real > standard way to specify versions in Python, other than "use semantic > versioning." It is a common myth that Python uses semantic versioning. It doesn't.

[Python-ideas] Re: dict_items.__getitem__?

2021-10-10 Thread Stephen J. Turnbull
Steven D'Aprano writes: > On Sun, Oct 10, 2021 at 01:51:52AM +0900, Stephen J. Turnbull wrote: > > Christopher Barker writes: > > > > > But last time, one of the use cases was "get [an arbitrary] item > > > from a dict", and there really is not a terribly easy (and > > > efficient) way

[Python-ideas] Re: Adding a Version type

2021-10-10 Thread Steven D'Aprano
On Sat, Oct 09, 2021 at 08:16:58PM -0600, Finn Mason wrote: > import sys > if sys.version_info < (3, 6): > # Yell at the user Please, version checking is usually an anti-pattern! You should use feature detection whenever possible, not version checking. For example, if you need the lcm

[Python-ideas] There must be a better way to do class-attributes -- allow descriptor.__set__ on `type`, not just `object`

2021-10-10 Thread Randolf Scholz
Over the past few weeks/months I have had on an off issues with the way python handles class-attributes. Consider the default way to do it: ``` class A: attr = 2 """Docstring of the attribute""" ``` There are 2 main issues I have with this way of setting class-attributes: 1. It does

[Python-ideas] Re: dict_items.__getitem__?

2021-10-10 Thread Paul Moore
On Sun, 10 Oct 2021 at 05:06, Finn Mason wrote: > > Let's get back to the original topic. Should `dict.items()` be indexable now > that dicts are ordered? I say yes. Why shouldn't it? I say no. "Why shouldn't it?" isn't sufficient justification for a change. Because it costs someone time and

[Python-ideas] Re: Adding a Version type

2021-10-10 Thread Paul Moore
On Sun, 10 Oct 2021 at 03:20, Finn Mason wrote: > > Hello all, > > I was thinking about the following idioms: > > __version__ = "1.0" > > import sys > if sys.version_info < (3, 6): > # Yell at the user > > > I feel like there could be a better way to define versions. There's no real >