New submission from Nic Watson:

The assertion:

  File "/usr/lib/python3.6/uuid.py", line 150, in __init__
    assert isinstance(bytes, bytes_), repr(bytes)

is too specific (and IMHO, unpythonic).  One may want to pass a bytearray or a 
memoryview.  See int.from_bytes for an example that takes "bytes" but accepts 
anything that acts like a bytes.

A simple solution may be to delete the assertion (it worked for me).

Example code:

import uuid

b = uuid.uuid1().bytes
ba = bytearray(b)
print(uuid.UUID(bytes=b))

# another API that works similarly, accepts a bytearray
print(int.from_bytes(ba, byteorder='big'))

# fails on assertion
print(uuid.UUID(bytes=ba))

----------
components: Extension Modules
messages: 289045
nosy: jnwatson
priority: normal
severity: normal
status: open
title: UUID bytes constructor has too-tight an assertion
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29729>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to