Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:

Not always the constructor accept an instance of the same class. I'm sure that 
this is not true in the majority of cases.

The constructor of int accepts an instance of int and the constructor of tuple 
accepts an instance of tuple because the constructor of int accepts an 
arbitrary real number, and the constructor of tuple accepts an arbitrary 
iterable, and int and tuple are a real number and an iterable correspondingly. 
There is no reason to forbid accepting an instance of the same class in these 
cases.

In contrary, the UUID constructor accepts a hexadecimal string, but UUID itself 
is not a hexadecimal string. Similarly the range constructor doesn't accept a 
range instance, and the file constructor doesn't accept a file instance.

>>> range(range(3))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'range' object cannot be interpreted as an integer
>>> io.FileIO(io.FileIO('/dev/null'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: expected str, bytes or os.PathLike object, not _io.FileIO

For converting an existing UUID instance to UUID you can can first convert it 
to str:

    newvalue = uuid.UUID(str(oldvalue))

Or better avoid the conversion at all.

    if isisnstance(oldvalue, uuid.UUID):
        newvalue = oldvalue
    else:
        newvalue = uuid.UUID(oldvalue)

----------
nosy: +serhiy.storchaka

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

Reply via email to