[New-bugs-announce] [issue35115] UUID objects can't be casted by `hex()`
fcurella
report at bugs.python.org
Tue Oct 30 11:12:16 EDT 2018
New submission from fcurella <flavio.curella at gmail.com>:
Casting a UUID to an `int` or to a string works as expected:
```
import uuid
value = uuid.UUID()
str(value)
int(value)
```
but casting to an `hex()` raises an exception:
```
import uuid
value = uuid.UUID()
# uuid instances already have the correct value stored in the `.hex` attribute
value.hex
# this raises `TypeError: 'UUID' object cannot be interpreted as an integer`
hex(value)
# this behaves correctly
hex(value.int)
```
Adding support for `hex()` should be simple enough as adding the following to the UUID class in https://github.com/python/cpython/blob/54752533b2ed1c898ffe5ec2e795c6910ee46a39/Lib/uuid.py#L69:
```
def __index__(self):
return self.int
```
----------
components: Library (Lib)
messages: 328929
nosy: fcurella
priority: normal
severity: normal
status: open
title: UUID objects can't be casted by `hex()`
type: behavior
versions: Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35115>
_______________________________________
More information about the New-bugs-announce
mailing list