Message322908
> Right now, you really gotta jump through hoops
> in some cases if you only want to use __new__
> and don't care about __init__
I'm now sure I see the difficulty. It is easy to define a classes with __new__ and without __init__:
>>> class A:
def __new__(cls, *args):
print('New called with', cls, 'and', args)
return object.__new__(cls)
>>> a = A(10, 20, 30)
New called with <class '__main__.A'> and (10, 20, 30)
>>> isinstance(a, A)
True
> Like __hash__, allow setting MyClass.__init__ to None
FWIW, the API for hashing being set-to-None wasn't done because we like it (there a numerous downsides). It was done because we needed hashing to be on by default and there needed to be a way to turn it off. The downsides are that it confuses users, it is hard to teach and remember, and it adds a branch to various APIs which would then need to test for None. Instead, we prefer the pattern of having object() provide a default dummy method that either does nothing or gives up (like object.__init__ or the various rich comparison methods for object). This simplifies downstream code than doesn't have to check for a rare special case. |
|
Date |
User |
Action |
Args |
2018-08-02 03:17:08 | rhettinger | set | recipients:
+ rhettinger, bup |
2018-08-02 03:17:08 | rhettinger | set | messageid: <1533179828.95.0.56676864532.issue34314@psf.upfronthosting.co.za> |
2018-08-02 03:17:08 | rhettinger | link | issue34314 messages |
2018-08-02 03:17:08 | rhettinger | create | |
|