[Python-ideas] Re: Escapes inside curly braces in f-strings

2020-06-30 Thread Guido van Rossum
On Mon, Jun 29, 2020 at 21:30 MRAB wrote: > On 2020-06-30 02:14, Steven D'Aprano wrote: > [snip] > > Counter-proposal: hex escapes allow optional curly brackets, similar to > > unicode name escapes. You could even allow spaces within the braces, for > > grouping: > > > > # Existing: > >

[Python-ideas] Add __eq__ to colletions.abc.Sequence ?

2020-06-30 Thread Joao S. O. Bueno
Is there any reason why collections.abc.[Sequence|MutableSequence] do not have "__eq__" for free? I was writing some tests now and was caught by surprise there. (chcking the docs, if my custom MutbaleSequence also inherits from "collections.abc.Set" I will have working "__eq__" - and "__ne__", me

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-06-30 Thread Christopher Barker
> > > But we're not talking about *dict*, we're talking about dict.items which > returns a set-like object: > > py> from collections.abc import Set > py> isinstance({}.items(), Set) > True > > So dict.items isn't subscriptable because it's an unordered set, not a > sequence. Or is it

[Python-ideas] Re: Python GIL Thoughts

2020-06-30 Thread redradist
Brett Cannon wrote: > It's a discussion issue. PEP 554 is trying to focus on the API of > subinterpreters and doesn't want to distract from that by bringing the GIL > into it. > That being said, the general expectation from everyone involved is there > will be a perl-interpreter GIL. > On Sat, Jun

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-06-30 Thread Steven D'Aprano
On Mon, Jun 29, 2020 at 11:02:54PM -0700, Christopher Barker wrote: > > So dict.items isn't subscriptable because it's an unordered set, not a > > sequence. > > > Or is it a set because it can’t be indexed? If I have the history right, > dict.items was first implemented with the “old” dict imple

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-06-30 Thread Stestagg
Hi A quick collection of responses: But we're not talking about *dict*, we're talking about dict.items which > returns a set-like object: > > py> from collections.abc import Set > py> isinstance({}.items(), Set) > True > > This property is nice, as .keys() (for example) can operate l

[Python-ideas] Re: Add __eq__ to colletions.abc.Sequence ?

2020-06-30 Thread Guido van Rossum
I don't recall why this was done. It seems somewhat odd, since Set and Mapping in the same module do have __eq__. I don't care much for the default implementation though. (I don't understand why you would want to inherit from both Sequence and Set -- and certainly the resulting mongrel type would

[Python-ideas] Re: Escapes inside curly braces in f-strings

2020-06-30 Thread Chris Angelico
On Tue, Jun 30, 2020 at 2:28 PM MRAB wrote: > > On 2020-06-30 02:14, Steven D'Aprano wrote: > [snip] > > Counter-proposal: hex escapes allow optional curly brackets, similar to > > unicode name escapes. You could even allow spaces within the braces, for > > grouping: > > > > # Existing: > >

[Python-ideas] Re: Escapes inside curly braces in f-strings

2020-06-30 Thread MRAB
On 2020-06-30 13:25, Chris Angelico wrote: On Tue, Jun 30, 2020 at 2:28 PM MRAB wrote: On 2020-06-30 02:14, Steven D'Aprano wrote: [snip] > Counter-proposal: hex escapes allow optional curly brackets, similar to > unicode name escapes. You could even allow spaces within the braces, for > group

[Python-ideas] Re: Add __eq__ to colletions.abc.Sequence ?

2020-06-30 Thread Joao S. O. Bueno
On Tue, 30 Jun 2020 at 11:57, Guido van Rossum wrote: > I don't recall why this was done. It seems somewhat odd, since Set and > Mapping in the same module do have __eq__. I don't care much for the > default implementation though. > > (I don't understand why you would want to inherit from both Se

[Python-ideas] Re: Escapes inside curly braces in f-strings

2020-06-30 Thread Chris Angelico
On Wed, Jul 1, 2020 at 1:57 AM MRAB wrote: > > On 2020-06-30 13:25, Chris Angelico wrote: > > On Tue, Jun 30, 2020 at 2:28 PM MRAB wrote: > >> > >> On 2020-06-30 02:14, Steven D'Aprano wrote: > >> [snip] > >> > Counter-proposal: hex escapes allow optional curly brackets, similar to > >> > unicode

[Python-ideas] Re: Escapes inside curly braces in f-strings

2020-06-30 Thread MRAB
On 2020-06-30 17:20, Chris Angelico wrote: On Wed, Jul 1, 2020 at 1:57 AM MRAB wrote: On 2020-06-30 13:25, Chris Angelico wrote: > On Tue, Jun 30, 2020 at 2:28 PM MRAB wrote: >> >> On 2020-06-30 02:14, Steven D'Aprano wrote: >> [snip] >> > Counter-proposal: hex escapes allow optional curly br

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-06-30 Thread Christopher Barker
On Tue, Jun 30, 2020 at 5:35 AM Steven D'Aprano wrote: > On Mon, Jun 29, 2020 at 11:02:54PM -0700, Christopher Barker wrote: > > > Or is it a set because it can’t be indexed? If I have the history right, > > dict.items was first implemented with the “old” dict implementation, > which > > did no

[Python-ideas] Re: Escapes inside curly braces in f-strings

2020-06-30 Thread Mikhail V
On Tue, Jun 30, 2020 at 5:05 AM Steven D'Aprano wrote: > For single-character escape codes, I see no benefit at all to this, only > disadvantages. However I do see a tiny potential benefit to hex escapes, > for the rare occassions that they are immediately followed by something > that looks like

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-06-30 Thread Rob Cliffe via Python-ideas
On 30/06/2020 04:08, Steven D'Aprano wrote: We can write inefficient code because dicts do *not* support index access: for i in range(len(d)): for j,item in enumerate(d.items()): if j == i: do(item) We certainly can.  The above is no different (apar

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-06-30 Thread Rhodri James
On 30/06/2020 18:31, Christopher Barker wrote: The first improvement on that was the iter* methods, and then (inspired by JAVA) it was determined that we could have view objects that could provide efficient iterators, and also set-like behavior. But I don't see any comments in the PEP about why i

[Python-ideas] Re: What about having a .get(index, default) method for arrays like we have for dicts?

2020-06-30 Thread Alex Hall
I think I'm missing something. Daniel wants a `list.get` method with similar semantics to `dict.get`. So instead of writing: ``` try: x = lst[i] except IndexError: x = default ``` one could write `x = lst.get(i, default)`. How would you rewrite that with PEP 505? I've also wanted this a

[Python-ideas] Re: Python GIL Thoughts

2020-06-30 Thread Brett Cannon
On Tue, Jun 30, 2020 at 5:26 AM wrote: > Brett Cannon wrote: > > It's a discussion issue. PEP 554 is trying to focus on the API of > > subinterpreters and doesn't want to distract from that by bringing the > GIL > > into it. > > That being said, the general expectation from everyone involved is t

[Python-ideas] Re: What about having a .get(index, default) method for arrays like we have for dicts?

2020-06-30 Thread Juancarlo Añez
Hello! Which would be the use cases for this feature? I can't think of one. I think that "nice to have" leads to the ways of Perl. Regards, On Sat, Jun 27, 2020 at 9:34 AM Daniel. wrote: > When I need to traverse nested dicts, is a common pattern to do > > somedict.get('foo', {}).get('bar',

[Python-ideas] Re: What about having a .get(index, default) method for arrays like we have for dicts?

2020-06-30 Thread Daniel.
I just want to make clear that safe navegator is enough to deal with this. Now that this is clear, the use case is almost always the same. I received some json as response and want to extract a nested value. The way I'm doing this today is overloading an infix operator (I'm using >>) to emulate s

[Python-ideas] Re: What about having a .get(index, default) method for arrays like we have for dicts?

2020-06-30 Thread MRAB
On 2020-06-30 23:26, Daniel. wrote: I just want to make clear that safe navegator is enough to deal with this. Now that this is clear, the use case is almost always the same. I received some json as response and want to extract a nested value. The way I'm doing this today is overloading an in

[Python-ideas] Re: What about having a .get(index, default) method for arrays like we have for dicts?

2020-06-30 Thread Alexander Hill
toolz.get_in is designed for exactly this. https://toolz.readthedocs.io/en/latest/api.html#toolz.dicttoolz.get_in The whole library is great! Alex On Wed, 1 Jul 2020 at 8:03 am, MRAB wrote: > On 2020-06-30 23:26, Daniel. wrote: > > I just want to make clear that safe navegator is enough to de

[Python-ideas] Re: Escapes inside curly braces in f-strings

2020-06-30 Thread Steven D'Aprano
On Tue, Jun 30, 2020 at 09:04:15PM +0300, Mikhail V wrote: > > Counter-proposal: hex escapes allow optional curly brackets, similar to > > unicode name escapes. You could even allow spaces within the braces, for > > grouping: > > > > # Proposed enhancement: > > "\x{2b}2c" # '+2c' > >

[Python-ideas] Re: Escapes inside curly braces in f-strings

2020-06-30 Thread Steven D'Aprano
On Tue, Jun 30, 2020 at 10:25:45PM +1000, Chris Angelico wrote: > Be careful of semantics here. I'm not sure which languages do what, > but I just checked Perl, and "\x{1234}" is equivalent to Python's > "\u1234", not to "\x12\x34". This proposal is for the latter, which > could be sneakily confus

[Python-ideas] Re: What about having a .get(index, default) method for arrays like we have for dicts?

2020-06-30 Thread David Lowry-Duda
Very similar things could be said about dict.get too, no? It's easy to write your own function that does the same thing or to catch an exception. On the other hand, it seems far more likely to miss keys in a dictionary than it is to repeatedly mistake indices in a list. > Which would be the us

[Python-ideas] Re: What about having a .get(index, default) method for arrays like we have for dicts?

2020-06-30 Thread Christopher Barker
On Tue, Jun 30, 2020 at 8:55 PM David Lowry-Duda wrote: > On the other hand, it seems far more likely to miss keys in a dictionary > than it is to repeatedly mistake indices in a list. > exactly -- dict keys are arbitrary, and it's pretty common to store "sparse" data by simply leaving out the k

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-06-30 Thread Christopher Barker
On Tue, Jun 30, 2020 at 11:55 AM Rhodri James wrote: > On 30/06/2020 18:31, Christopher Barker wrote: > > The first improvement on that was the iter* methods, and then (inspired > by > > JAVA) it was determined that we could have view objects that could > provide > > efficient iterators, and also

[Python-ideas] Re: Add __eq__ to colletions.abc.Sequence ?

2020-06-30 Thread Random832
On Tue, Jun 30, 2020, at 10:57, Guido van Rossum wrote: > I don't recall why this was done. It seems somewhat odd, since Set and > Mapping in the same module do have __eq__. I don't care much for the > default implementation though. > > > > Anyway, maybe there is a reason it is not a given. Any

[Python-ideas] Ability to use own string types

2020-06-30 Thread artem6191
This will be helpful for python linters, own data types, etc. Example: class SQL_String(str): @property def __chr__(self): # SQL_string.__chr__ will return string that need to be before string start return 's' def __check__(self): # This method will be called by intep