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

2021-11-08 Thread Ethan Furman
On 11/8/21 4:45 AM, Victor Stinner wrote: > Is it implement "like" ascii(obj).encode("ascii") but with minor > changes? What changes? It works like `str()`, but you get ascii-encoded bytes (or an exception if that's not possible). The difference with the built-in ascii is the absence of extra

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

2021-11-08 Thread Tim Peters
[Ethan Furman ] > When is an empty container contained by a non-empty container? That depends on how the non-empty container's type defines __contains__. The "stringish" types (str, byte, bytearray) work _very_ differently from others (list, set, tuple) in this respect. t in x for the latter

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

2021-11-08 Thread Guido van Rossum
On Mon, Nov 8, 2021 at 1:43 PM Ethan Furman wrote: > When is an empty container contained by a non-empty container? > > For example: > > {} in {1:'a', 'b':2} <-- TypeError because of hashability > (You accidentally wrote a square close bracket, but I know you meant a curly close brace. :-}

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

2021-11-08 Thread Cameron Simpson
On 08Nov2021 23:32, MRAB wrote: >On 2021-11-08 22:10, Cameron Simpson wrote: >>>{} in {1:'a', 'b':2] <-- TypeError because of hashability >>>set() in {1, 2, 'a', 'b'} <-- ditto >>>[] in ['a', 'b', 1, 2] <-- False >> >>Right. Also, the members are not dicts or sets, respectively. >> >More

[Python-Dev] containment and the empty container

2021-11-08 Thread Ethan Furman
When is an empty container contained by a non-empty container? For example: {} in {1:'a', 'b':2] <-- TypeError because of hashability set() in {1, 2, 'a', 'b'} <-- ditto [] in ['a', 'b', 1, 2] <-- False '' in 'a1b2' <-- True SomeFlag.nothing in SomeFlag.something <-- ???

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

2021-11-08 Thread MRAB
On 2021-11-09 00:27, Cameron Simpson wrote: On 08Nov2021 23:32, MRAB wrote: >On 2021-11-08 22:10, Cameron Simpson wrote: >>>{} in {1:'a', 'b':2] <-- TypeError because of hashability >>>set() in {1, 2, 'a', 'b'} <-- ditto >>>[] in ['a', 'b', 1, 2] <-- False >> >>Right. Also, the members are

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

2021-11-08 Thread Cameron Simpson
Note: I know you understand all this, I'm not "explaining" how things work below, I'm explaining how/why I think about how these work. On 08Nov2021 13:43, Ethan Furman wrote: >When is an empty container contained by a non-empty container? [...] >For example: > >{} in {1:'a', 'b':2] <--

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

2021-11-08 Thread Steven D'Aprano
On Mon, Nov 08, 2021 at 01:43:03PM -0800, Ethan Furman wrote: > When is an empty container contained by a non-empty container? [...] > SomeFlag.nothing in SomeFlag.something <-- ??? I don't think that consistency with other containers is particularly relevant here. More useful is consistency

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

2021-11-08 Thread MRAB
On 2021-11-08 22:10, Cameron Simpson wrote: Note: I know you understand all this, I'm not "explaining" how things work below, I'm explaining how/why I think about how these work. On 08Nov2021 13:43, Ethan Furman wrote: When is an empty container contained by a non-empty container? [...] For

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

2021-11-08 Thread Ethan Furman
Let's use a concrete example: `re.RegexFlag` ``` Help on function match in module re: match(pattern, string, flags=0) Try to apply the pattern at the start of the string, returning a Match object, or None if no match was found. ``` In use we have: result = re.match('present',

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

2021-11-08 Thread Rob Cliffe via Python-Dev
On 08/11/2021 21:43, Ethan Furman wrote: When is an empty container contained by a non-empty container? For example: These examples are not at all analogous.  `a in b` has different meanings for different classes of b. {} in {1:'a', 'b':2]   <-- TypeError because of hashability `x in aDict`

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

2021-11-08 Thread Guido van Rossum
On Mon, Nov 8, 2021 at 7:26 PM Ethan Furman wrote: > Let's use a concrete example: `re.RegexFlag` > > ``` > Help on function match in module re: > > match(pattern, string, flags=0) > Try to apply the pattern at the start of the string, returning > a Match object, or None if no match

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

2021-11-08 Thread John Melendowski
I think he's confusing the fact that empty is a subset of every set ___ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message

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

2021-11-08 Thread Ethan Furman
Something to keep in mind as these discussions continue: Enums are already unusual in several ways: - the class itself is iterable - the class itself supports containment checks of its enum members - the enum members are created, and guaranteed singletons, during class creation - the enum

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

2021-11-08 Thread Victor Stinner
The ascii() constructor is not well specified by the PEP. There are only a few examples. I don't understand how it's supposed by be implemented. Would you mind to elaborate its specification? Is it implement "like" ascii(obj).encode("ascii") but with minor changes? What changes? Victor

[Python-Dev] Re: Oh wow, this is really impressive

2021-11-08 Thread Victor Stinner
What's New in Python 3.10 lists other suggestions and enhanced error messages: https://docs.python.org/dev/whatsnew/3.10.html#better-error-messages Victor On Fri, Oct 29, 2021 at 7:22 PM Steven D'Aprano wrote: > > I was using Python 3.10 and got this NameError when I mistyped a name: > >