New submission from fcurella <flavio.cure...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue35115>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

  • ... fcurella
    • ... fcurella
    • ... Serhiy Storchaka
    • ... Ronald Oussoren
    • ... fcurella
    • ... Serhiy Storchaka
    • ... శ్రీనివాస్ రెడ్డి తాటిపర్తి
    • ... Mark Dickinson
    • ... Serhiy Storchaka
    • ... fcurella
    • ... Mark Dickinson

Reply via email to