Message330171
My personal opinion is: support abstractmethod only when the descriptor is useful for define interface with ABC.
In case of cached_property, it's not. It is just a property as interface level. Caching is just an implementation.
In case of update_wrapper, it's too generic. A decorated function may be used while define interface, but it's a rare case. So no need to support it.
In case of singledispatch, I think it is not used in ABC, like cached_property. But it has shipped in Python already. We shouldn't remove it easily.
In case of partialmethod... it's considerable. I don't use ABC much, and I never use partialmethod. So this example is very artificial.
class MyABC(abc.ABC):
@abstractmethod
def set_foo(self, v):
pass
reset_foo = partialmethod(set_foo, None)
When they subclass of MyABC, they need to override both of `set_foo` and `reset_foo`. Otherwise, reset_foo is bound to MyABC.set_foo, not subclass' one.
So __isabstractmethod__ support in partialmethod is not just a "commet as a code".
On the other hand, this example can be written as:
class MyABC(abc.ABC):
@abstractmethod
def set_foo(self, v):
pass
@abstractmethod
def reset_foo(self):
pass
Or it can use lazy binding too:
class MyABC(abc.ABC):
@abstractmethod
def set_foo(self, v):
pass
# No need to override if default implementation is OK
def reset_foo(self):
self.set_foo(None)
I am not sure __isabstractmethod__ support in partialmethod is really useful. |
|
Date |
User |
Action |
Args |
2018-11-21 06:24:35 | methane | set | recipients:
+ methane, vstinner, carljm, serhiy.storchaka, levkivskyi, sir-sigurd, mwilbz |
2018-11-21 06:24:35 | methane | set | messageid: <1542781475.82.0.788709270274.issue34995@psf.upfronthosting.co.za> |
2018-11-21 06:24:35 | methane | link | issue34995 messages |
2018-11-21 06:24:34 | methane | create | |
|