Opened 3 years ago
Closed 3 years ago
#33415 closed Bug (needsinfo)
@classproperty breakes @abc.abstractmethod
Reported by: | Mateusz Legięcki | Owned by: | nobody |
---|---|---|---|
Component: | Utilities | Version: | 4.0 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I'm trying to do something weird, but I found an interesting bug:
Example:
import abc import inspect from django.utils.functional import classproperty class A(metaclass=abc.ABCMeta): @classproperty @abc.abstractmethod def x(self): pass print(inspect.isabstract(A)) # False
This prints False. It should print True, due to method x is not implemented.
It works a little bit better when @abc.abstractmethod is first decorator. Then class is recoginsed as abstract. However, subclass of this class is always not-abstract.
Example:
import abc import inspect from django.utils.functional import classproperty class A(metaclass=abc.ABCMeta): @abc.abstractmethod @classproperty def x(self): pass class B(A, metaclass=abc.ABCMeta): pass print(inspect.isabstract(A)) # True print(inspect.isabstract(B)) # False
Note:
See TracTickets
for help on using tickets.
Other decorators also break
isabstract()
, e.g.@cached_property
. I'm not sure how to fix it and is it worth additional complexity. Can you provide PoC?