[Python-Dev] Re: Enum and the Standard Library

2020-09-22 Thread Serhiy Storchaka
19.09.20 00:44, Ethan Furman пише: > I'm looking for arguments relating to: > > - should _convert_ make the default __repr__ be module_name.member_name? In most cases enums with _convert_ are used to replace old module globals. They are accessible as module_name.member_name and always used as mod

[Python-Dev] Re: unable to create PR on github

2020-09-22 Thread Antoine Pitrou
On Mon, 21 Sep 2020 20:56:18 -0700 Ethan Furman wrote: > And even more data: > > I added a body to the PR I was originally having trouble with: >button stayed gray > > I went away for a while, say 5 - 10 minutes, and when I went back to > that screen the button was green. I created the PR.

[Python-Dev] Understanding why object defines rich comparison methods

2020-09-22 Thread Steven D'Aprano
Why does `object` define rich comparison dunders `__lt__` etc? As far as I can tell, `object.__lt__` etc always return NotImplemented. Merely inheriting from object isn't enough to have comparisons work. So why do they exist at all? Other "do nothing" dunders such as `__add__` aren't defined.

[Python-Dev] Re: Tagged pointer experiment: need help to optimize

2020-09-22 Thread Victor Stinner
Le lun. 21 sept. 2020 à 21:46, Antoine Pitrou a écrit : > > The main benefit is the memory usage. For example, list(range(200)) > > uses 1656 bytes instead of 7262 (4x less memory). > > Hmm, how come? Aren't those tiny integers singletons already? These numbers come from the code: import sys

[Python-Dev] Re: Understanding why object defines rich comparison methods

2020-09-22 Thread Emily Bowman
NotImplemented is like a pure virtual function; failing to implement it tells you that you forgot part of the contract, except at runtime instead of compile time. So if you never need them, you're free to elide them, but if you want full compatibility, you need to implement every part of it. If so

[Python-Dev] Re: Understanding why object defines rich comparison methods

2020-09-22 Thread Serhiy Storchaka
22.09.20 12:48, Steven D'Aprano пише: > Why does `object` define rich comparison dunders `__lt__` etc? > > As far as I can tell, `object.__lt__` etc always return NotImplemented. > Merely inheriting from object isn't enough to have comparisons work. So > why do they exist at all? Other "do nothi

[Python-Dev] Re: Understanding why object defines rich comparison methods

2020-09-22 Thread Steven D'Aprano
On Tue, Sep 22, 2020 at 02:13:46PM +0300, Serhiy Storchaka wrote: > 22.09.20 12:48, Steven D'Aprano пише: > > Why does `object` define rich comparison dunders `__lt__` etc? > Because object.__eq__ and object.__ne__ exist. If you define slot > tp_richcompare in C, it is exposed as 6 methods __eq__,

[Python-Dev] Re: Understanding why object defines rich comparison methods

2020-09-22 Thread Nick Coghlan
On Tue., 22 Sep. 2020, 10:25 pm Steven D'Aprano, wrote: > On Tue, Sep 22, 2020 at 02:13:46PM +0300, Serhiy Storchaka wrote: > > 22.09.20 12:48, Steven D'Aprano пише: > > > Why does `object` define rich comparison dunders `__lt__` etc? > > > Because object.__eq__ and object.__ne__ exist. If you de

[Python-Dev] Re: Enum and the Standard Library

2020-09-22 Thread Ethan Furman
On 9/22/20 12:11 AM, Serhiy Storchaka wrote: The only exception is StrEnum -- overriding __str__ of str subclass may be not safe. Some code will call str() implicitly, other will read the string content of the object directly, and they will be different. Following up on that: >>> import e

[Python-Dev] Re: Tagged pointer experiment: need help to optimize

2020-09-22 Thread Mark Shannon
Hi Victor, There are plenty of reasons for a new, cleaner C-API. However, performance isn't really one of them. The C-API is not much of an obstacle to improving the performance of CPython, at the moment. There are implementation details that leak into the API, but they are only an issue when w

[Python-Dev] Re: Enum and the Standard Library

2020-09-22 Thread Serhiy Storchaka
22.09.20 16:57, Ethan Furman пише: > On 9/22/20 12:11 AM, Serhiy Storchaka wrote: >> The only exception is StrEnum -- overriding __str__ of str >> subclass may be not safe. Some code will call str() implicitly, other >> will read the string content of the object directly, and they will be >> differ

[Python-Dev] Re: Tagged pointer experiment: need help to optimize

2020-09-22 Thread Greg Ewing
On 22/09/20 10:06 pm, Victor Stinner wrote: I wrote a simple implementation which leaves the code as it is, but "unbox" tagged pointers when a function access directly object members. Example in listobject.c: vl = (PyLongObject*)_Py_TAGPTR_UNBOX(v); wl = (PyLongObject*)_Py_TAGPTR_UNBOX

[Python-Dev] Re: Understanding why object defines rich comparison methods

2020-09-22 Thread Greg Ewing
On 23/09/20 12:20 am, Steven D'Aprano wrote: Presumably back when rich comparisons were added, the choice would have been: - add one tp_richcompare slot to support all six methods; or - add six slots, one for each individual dunder in which case the first option wastes much less space. I don

[Python-Dev] Re: Tagged pointer experiment: need help to optimize

2020-09-22 Thread Guido van Rossum
On Tue, Sep 22, 2020 at 4:58 PM Greg Ewing wrote: > What are you trying to achieve by using tagged pointers? > > It seems to me that in a dynamic environment like Python, tagged > pointer tricks are only ever going to reduce memory usage, not > make anything faster, and in fact can only make thin