Author serhiy.storchaka
Recipients mjpieters, serhiy.storchaka, ztane
Date 2017-11-22.13:35:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1511357750.71.0.213398074469.issue32112@psf.upfronthosting.co.za>
In-reply-to
Content
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)
History
Date User Action Args
2017-11-22 13:35:50serhiy.storchakasetrecipients: + serhiy.storchaka, mjpieters, ztane
2017-11-22 13:35:50serhiy.storchakasetmessageid: <1511357750.71.0.213398074469.issue32112@psf.upfronthosting.co.za>
2017-11-22 13:35:50serhiy.storchakalinkissue32112 messages
2017-11-22 13:35:50serhiy.storchakacreate