[issue35115] UUID objects can't be casted by `hex()`

2018-10-31 Thread fcurella


fcurella  added the comment:

I'm not sure what can be done to make UUIDs work with `hex()`. The only way I 
see is to add back something _like_ `__hex__`, but with a different name.

But in that case, I can see how the same arguments that were originally brought 
up against `__hex__` could apply to the new dunder method.

I'm closing the issue as 'wont fix'.

--
resolution:  -> wont fix
stage: patch review -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue35115>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35115] UUID objects can't be casted by `hex()`

2018-10-30 Thread fcurella


Change by fcurella :


--
status:  -> open

___
Python tracker 
<https://bugs.python.org/issue35115>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35115] UUID objects can't be casted by `hex()`

2018-10-30 Thread fcurella


fcurella  added the comment:

I must admit I was surprised to find out that `hex()` uses `__index__` (which 
is supposed to return an integer) and not something like a `__hex__` method 
returning the hex.

Maybe we should change the behaviour of `hex()` instead? (in a 
backward-compatible way, of course)

--

___
Python tracker 
<https://bugs.python.org/issue35115>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35115] UUID objects can't be casted by `hex()`

2018-10-30 Thread fcurella


Change by fcurella :


--
keywords: +patch
pull_requests: +9557
stage:  -> patch review

___
Python tracker 
<https://bugs.python.org/issue35115>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35115] UUID objects can't be casted by `hex()`

2018-10-30 Thread fcurella


New submission from fcurella :

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 
<https://bugs.python.org/issue35115>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com