Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue7380] uuid.UUID.bytes gives a bytearray() instead of bytes

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Nov 23, 2009, 4:33 AM

Post #1 of 8 (385 views)
Permalink
[issue7380] uuid.UUID.bytes gives a bytearray() instead of bytes

New submission from flox <laxyf [at] yahoo>:

I've tried some experiments with module uuid, and I meet some
inconsistencies between the documentation, the docstring and the real
behavior of the module.

An interactive session is worth a thousand words:

>>> import uuid
>>> uuid.UUID(bytes='\x12\x34\x56\x78'*4)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.1/uuid.py", line 149, in __init__
assert isinstance(bytes, bytes_), repr(bytes)
AssertionError: '\x124Vx\x124Vx\x124Vx\x124Vx'
>>> uuid.UUID(bytes_le='\x78\x56\x34\x12\x34\x12\x78\x56' +
... '\x12\x34\x56\x78\x12\x34\x56\x78')
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/usr/lib/python3.1/uuid.py", line 144, in __init__
bytes_(reversed(bytes_le[6:8])) +
TypeError: 'str' object cannot be interpreted as an integer
>>>

Ok, the lines above are just parts of the documentation which need
update. But what is more confusing is the last example of the documentation.
http://docs.python.org/dev/py3k/library/uuid.html

Here is the interactive session:

>>> x = uuid.UUID('{00010203-0405-0607-0809-0a0b0c0d0e0f}')
>>> x.bytes
bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f')
>>> x.bytes_le
b'\x03\x02\x01\x00\x05\x04\x07\x06\x08\t\n\x0b\x0c\r\x0e\x0f'
>>>

Normally both attributes should get a "UUID as a 16-byte string",
according to the documentation. Only the endianness should do the
difference. I guess this one need a patch.


Finally, the docstring fails, too:

~ $ python3 -m doctest /usr/lib/python3.1/uuid.py
**********************************************************************
File "/usr/lib/python3.1/uuid.py", line 16, in uuid
Failed example:
uuid.uuid1()
Expected:
UUID('a8098c1a-f86e-11da-bd1a-00112444be1e')
Got:
UUID('e4bc8a38-d829-11de-9eee-0024e8bc58f0')
**********************************************************************
File "/usr/lib/python3.1/uuid.py", line 24, in uuid
Failed example:
uuid.uuid4()
Expected:
UUID('16fd2706-8baf-433b-82eb-8c7fada847da')
Got:
UUID('71588cf5-7a51-4d59-ad76-05fb6b932673')
**********************************************************************
File "/usr/lib/python3.1/uuid.py", line 39, in uuid
Failed example:
x.bytes
Expected:
b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'
Got:
bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f')
**********************************************************************
File "/usr/lib/python3.1/uuid.py", line 43, in uuid
Failed example:
uuid.UUID(bytes=x.bytes)
Exception raised:
Traceback (most recent call last):
File "/usr/lib/python3.1/doctest.py", line 1243, in __run
compileflags, 1), test.globs)
File "<doctest uuid[8]>", line 1, in <module>
uuid.UUID(bytes=x.bytes)
File "/usr/lib/python3.1/uuid.py", line 149, in __init__
assert isinstance(bytes, bytes_), repr(bytes)
AssertionError:
bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f')
**********************************************************************
1 items had failures:
4 of 9 in uuid
***Test Failed*** 4 failures.
~ $

----------
components: Library (Lib)
messages: 95622
nosy: flox
severity: normal
status: open
title: uuid.UUID.bytes gives a bytearray() instead of bytes
versions: Python 3.0, Python 3.1, Python 3.2

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7380>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 23, 2009, 4:47 AM

Post #2 of 8 (366 views)
Permalink
[issue7380] uuid.UUID.bytes gives a bytearray() instead of bytes [In reply to]

flox <laxyf [at] yahoo> added the comment:

Attached patch gives coherence:
* both UUID.bytes and UUID.bytes_le return a "bytes" object
* the random tests are explicitly skipped

Then the documentation needs fixing, too.

----------
keywords: +patch
Added file: http://bugs.python.org/file15385/issue7380_uuid.diff

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7380>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 23, 2009, 10:03 AM

Post #3 of 8 (360 views)
Permalink
[issue7380] uuid.UUID.bytes gives a bytearray() instead of bytes [In reply to]

flox <laxyf [at] yahoo> added the comment:

Patch with documentation included. (branches/py3k)

----------
assignee: -> georg.brandl
components: +Documentation
nosy: +georg.brandl
Added file: http://bugs.python.org/file15388/issue7380.diff

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7380>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 23, 2009, 10:05 AM

Post #4 of 8 (356 views)
Permalink
[issue7380] uuid.UUID.bytes gives a bytearray() instead of bytes [In reply to]

Changes by flox <laxyf [at] yahoo>:


Removed file: http://bugs.python.org/file15385/issue7380_uuid.diff

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7380>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Dec 1, 2009, 1:05 AM

Post #5 of 8 (315 views)
Permalink
[issue7380] uuid.UUID.bytes gives a bytearray() instead of bytes [In reply to]

Changes by flox <laxyf [at] yahoo>:


Added file: http://bugs.python.org/file15426/issue7380_py3k.diff

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7380>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Dec 1, 2009, 1:05 AM

Post #6 of 8 (316 views)
Permalink
[issue7380] uuid.UUID.bytes gives a bytearray() instead of bytes [In reply to]

Changes by flox <laxyf [at] yahoo>:


Removed file: http://bugs.python.org/file15388/issue7380.diff

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7380>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Dec 11, 2009, 10:00 AM

Post #7 of 8 (288 views)
Permalink
[issue7380] uuid.UUID.bytes gives a bytearray() instead of bytes [In reply to]

Changes by flox <laxyf [at] yahoo>:


----------
versions: -Python 3.0

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7380>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Dec 19, 2009, 10:23 AM

Post #8 of 8 (265 views)
Permalink
[issue7380] uuid.UUID.bytes gives a bytearray() instead of bytes [In reply to]

Georg Brandl <georg [at] python> added the comment:

Thanks, applied in r76895.

----------
resolution: -> accepted
status: open -> closed

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7380>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.