That looks expensive, esp. for objects implemented in Python — an extra dict entry plus a new unique int object. What is the problem you are trying to solve for these objects specifically? Just that the hex numbers look distracting doesn’t strike me as sufficient motivation.
On Sun, Jul 19, 2020 at 08:39 Serhiy Storchaka <storch...@gmail.com> wrote: > I have problem with the location of hexadecimal memory address in custom > reprs. > > <threading.BoundedSemaphore: 2/3 at 0x7ff4c26b3eb0> > > vs > > <threading.BoundedSemaphore at 0x7ff4c26b3eb0: 2/3> > > The long hexadecimal number makes the repr longer and distracts > attention from other useful information. We could get rid of it, but it > is useful if we want to distinguish objects of the same type. Although > it is hard to distinguish long hexadecimal numbers which differ only by > few digits in the middle. > > What if use serial numbers to differentiate instances? > > <threading.BoundedSemaphore #5: 2/3> > > where the serial number starts with 1 and increased for every new > instance of that type. > > The advantages are: > > * Shorter repr. > * Easier to distinguish different objects. > * The serial number is unique for the life of program and cannot be > reused (in contrary to id/memory address). > > The disadvantages are: > > * Increased object size and creation time. > > I do not propose to use serial numbers for all objects, because it would > increase the size of objects and the fixed-size integer can be > overflowed for some short-living objects created in mass (like numbers, > strings, tuples). But only for some custom objects implemented in > Python, for which size and creation time are not critical. I want to > start with synchronization objects in threading and multiprocessing > which did not have custom reprs, than change reprs of locks and asyncio > objects. > > Is it worth to do? > _______________________________________________ > 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/E6YEXMQ4OE5YGZGRP62JOLTAGBCL6RCX/ > Code of Conduct: http://python.org/psf/codeofconduct/ > -- --Guido (mobile)
_______________________________________________ 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/7BR5USRVLRE34KH53RPMFV43Z7TPXRH5/ Code of Conduct: http://python.org/psf/codeofconduct/