I'm subclassing UUID
and I was trying to figure out if UUID.hex
is a regular member or a method decorated with @property
. I had to look at the source code to figure it out, which left me wondering if there was another way.
>>> import uuid
>>> x = uuid.UUID('0000180000001000800000805f9b34fb')
>>> print([attr for attr in dir(x) if callable(getattr(x, attr))])
['__class__', '__delattr__', '__dir__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__int__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__']
>>> print([attr for attr in dir(x) if not callable(getattr(x, attr))])
['__doc__', '__module__', '__slots__', '__weakref__', 'bytes', 'bytes_le', 'clock_seq', 'clock_seq_hi_variant', 'clock_seq_low', 'fields', 'hex', 'int', 'is_safe', 'node', 'time', 'time_hi_version', 'time_low', 'time_mid', 'urn', 'variant', 'version']
The source code is:
@property
def hex(self):
return '%032x' % self.int
It's a method decorated with @property
. I was kinda expecting that hex
would show up as callable()
, but that's not the case. Is there any way I could tell that by examining the class or an object?
Thanks!