Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix UUID(bytes_le=16)
  • Loading branch information
vstinner committed Sep 28, 2017
commit a169e89e41323e92a930cfa133611be02a3859ad
2 changes: 2 additions & 0 deletions Lib/test/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,15 @@ def test_exceptions(self):
badvalue(lambda: self.uuid.UUID(bytes=b'abc'))
badvalue(lambda: self.uuid.UUID(bytes=b'\0'*15))
badvalue(lambda: self.uuid.UUID(bytes=b'\0'*17))
badtype(lambda: self.uuid.UUID(bytes=16))

# Badly formed bytes_le.
badtype(lambda: self.uuid.UUID(bytes_le='unicode'))
badtype(lambda: self.uuid.UUID(bytes_le='u'*16))
badvalue(lambda: self.uuid.UUID(bytes_le=b'abc'))
badvalue(lambda: self.uuid.UUID(bytes_le=b'\0'*15))
badvalue(lambda: self.uuid.UUID(bytes_le=b'\0'*17))
badtype(lambda: self.uuid.UUID(bytes_le=16))

# Badly formed fields.
badvalue(lambda: self.uuid.UUID(fields=(1,)))
Expand Down
3 changes: 2 additions & 1 deletion Lib/uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None,
raise ValueError('badly formed hexadecimal UUID string')
int = int_(hex, 16)
if bytes_le is not None:
if not isinstance(bytes_le, (bytes_, bytearray)):
# Don't cast int to bytes to get a TypeError above
if not isinstance(bytes_le, (bytes_, bytearray, int_)):
bytes_le = bytes_(bytes_le)
if len(bytes_le) != 16:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

By above in the comment, do you mean this check, which is actually below the comment? :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I removed the comment.

raise ValueError('bytes_le is not a 16-char string')
Expand Down