Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-35115 Add __index__ to UUID class #10244

Closed
wants to merge 4 commits into from

Conversation

fcurella
Copy link

@fcurella fcurella commented Oct 30, 2018

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:

class UUID:

def __index__(self):
    return self.int

https://bugs.python.org/issue35115

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

Copy link
Member

@tirkarthi tirkarthi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/python/cpython/pull/10244/files#diff-e2cd29d814548cea63c5269b8fd75effL163 should use self.uuid.UUID(hex_) since the for loop iteration variable is now changed to hex_.

@fcurella
Copy link
Author

issue closed as wont fix

@fcurella fcurella closed this Oct 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants