On 03/25/2020 06:53 PM, Ivan Pozdeev via Python-Dev wrote:
A diagnostic is always done by the same algorithm: 1) Identify the exact place in code where the problem manifests itself 2) Examine the state of the program at that moment to find out which if the values are wrong 3) Track the wrong value back to its origin Seeing an accurate repr() is required for step 2) -- to immediately detect if it's wrong or not.
Before Enum, the repr for socket.AF_UNIX was: 1 Not very useful for debugging.
If a repr() points to a reference rather than definition, I don't really know anything about the object that I'm looking at: that reference could as well be wrong, or could have been wrong at any moment in the past. I.e. such a repr() has negative informativity.
Whether it's <socket.AF_UNIX: 1> or <AddressFamily.AF_UNIX: 1> it has light-years more information than it used to (okay, maybe only light-minutes ;) )
Finding the definition, as opposed to merely a reference, is required for step 3).
Before Enum, if you had tried to find AF_UNIX and did a full Lib/*.py search you would have found some comments and a couple lines of code -- never a definition. And that's assuming you made the leap from 1 to AF_UNIX. You should add searching for from ... import * to your debugging list, because then you'll find: from _socket import *
To identify which code could have adversely affected the object's value, I must find both its implementation (for potential internal offenders) and references to it and objects of this type in general (for potential external offenders).
Finding the implementation might be a bit trickier with `socket.AF_UNIX', however: $ grep AddressFamily.AF_UNIX *.py ...(crickets)... $ grep socket.AF_UNIX *.py smtplib.py: self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) socketserver.py: address_family = socket.AF_UNIX socketserver.py: address_family = socket.AF_UNIX webbrowser.py: s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) Considering that stdlib Enums are almost all globally unique, and Enums created with _convert *are* globally unique, I think seeing the module instead of the class name is more helpful. Speaking of which, adding help() to your debugging list would also be, um, helpful: --> help(socket.AF_UNIX) Help on AddressFamily in module socket object: class AddressFamily(enum.IntEnum) | AddressFamily(value, names=None, *, module=None, qualname=None, type=None, start=1) | | An enumeration. | | ... As a reminder, the change under discussion only affects enums created from globally unique constants using the Enum._convert helper utility. -- ~Ethan~ _______________________________________________ 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 archived at https://mail.python.org/archives/list/python-dev@python.org/message/C55F5N4JHPCRLXJRDN5CGXYRZEARI2JT/ Code of Conduct: http://python.org/psf/codeofconduct/