Message71623
With immutable types, you must use __new__ instead. Passing the
arguments to __init__ is too late since the object is immutable and it
has already been built in memory, thus you can't initialize it with
another value.
>>> class B(bytes):
... def __new__(cls, *args, **kargs):
... print(args)
... return bytes.__new__(cls, *args, **kargs)
...
>>> b = B(b"foo")
(b'foo',)
>>> b
b'foo'
>>> type(b)
<class '__main__.B'> |
|
Date |
User |
Action |
Args |
2008-08-21 10:16:42 | pitrou | set | recipients:
+ pitrou, vstinner |
2008-08-21 10:16:42 | pitrou | set | messageid: <1219313802.53.0.306626140885.issue3630@psf.upfronthosting.co.za> |
2008-08-21 10:16:40 | pitrou | link | issue3630 messages |
2008-08-21 10:16:39 | pitrou | create | |
|