On Thu, Mar 26, 2020 at 12:08 PM Ivan Pozdeev via Python-Dev <python-dev@python.org> wrote: > > > On 26.03.2020 2:41, Chris Angelico wrote: > > On Thu, Mar 26, 2020 at 10:38 AM Ivan Pozdeev via Python-Dev > > <python-dev@python.org> wrote: > >> I'm skeptical about anything that hides an object's "true nature": this is > >> a major landmine in diagnostics because it lies to you about what > >> you are looking at and where to look for its implementation. > >> > >> E. g. in this case, AF_UNIX is a member of some entity called > >> "AddressFamily" -- so I would search the code for "AddressFamily" to see > >> what > >> I'm looking at and what else I can do with it. The fact that it's also > >> directly availabe from the `socket` module is incidental: it could be > >> as easily made available from anywhere else -- not even a module. > >> > > But if it's described as socket.AF_UNIX then you know where to go > > looking for it, > > No, I don't. https://docs.python.org/3/library/functions.html#repr sets the > standard -- thus the expectation -- for user-defined types: > "...otherwise the representation is a string enclosed in angle brackets that > contains the name of the type of the object together with > additional information often including the name and address of the object" -- > which this suggestion would be breaking. > > By this standard, "socket.AF_UNIX" looks like something defined directly at > module level. So I'll be looking for a definition at module > level -- and not find it. At which point, I'd suspect shenanigans like a > dynamic creation or assignment. Which can be absolutely anywhere! > And I'll be looking for the wrong thing still! >
"""For many types, this function makes an attempt to return a string that would yield an object with the same value when passed to eval()...""" >>> socket.AF_UNIX <AddressFamily.AF_UNIX: 1> If the repr were "socket.AF_UNIX", then that would indeed be a string that would yield an object with the same value. The current repr isn't wrong by this definition, but nor is the proposed change. Is it defined at module level? I couldn't care less; all that matters is that it is *accessible* at module level. I don't have to say "socket.AddressFamily.AF_UNIX". ChrisA _______________________________________________ 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/4Q7SVP6ZXR4SAPMDWYGPH7OWX5YXI44M/ Code of Conduct: http://python.org/psf/codeofconduct/