[docs] [issue19164] Update uuid.UUID TypeError exception: integer should not be an argument.

Marco Buccini report at bugs.python.org
Fri Oct 4 13:18:10 CEST 2013


New submission from Marco Buccini:

When you try to use uuid.UUID() without arguments you get a TypeError exception saying that you can actually use an integer (while you cannot). 

Python 2.6.8 (default, Apr 26 2013, 16:24:53) 
[GCC 4.6.3] on linux2
>>> uuid.UUID()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/uuid.py", line 129, in __init__
    raise TypeError('need one of hex, bytes, bytes_le, fields, or int')
TypeError: need one of hex, bytes, bytes_le, fields, or int

>>> uuid.UUID(uuid.uuid4().int)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/uuid.py", line 131, in __init__
    hex = hex.replace('urn:', '').replace('uuid:', '')
AttributeError: 'long' object has no attribute 'replace'

So, let's check with an integer - maybe an int has 'replace'.
>>> uuid.UUID(1231231)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/uuid.py", line 131, in __init__
    hex = hex.replace('urn:', '').replace('uuid:', '')
AttributeError: 'int' object has no attribute 'replace'

No, it doesn't. Anyway, with a propery hex value, it works (of course!).

>>> uuid.UUID(uuid.uuid4().hex)
UUID('89b1283d-c32e-4b8a-a9e3-a699445fdd4d')

----------
assignee: docs at python
components: Documentation
messages: 198943
nosy: docs at python, makronized
priority: normal
severity: normal
status: open
title: Update uuid.UUID TypeError exception: integer should not be an argument.
type: behavior
versions: Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19164>
_______________________________________


More information about the docs mailing list