[Django] #33415: @classproperty breakes @abc.abstractmethod

4 views
Skip to first unread message

Django

unread,
Jan 6, 2022, 12:59:17 PM1/6/22
to django-...@googlegroups.com
#33415: @classproperty breakes @abc.abstractmethod
--------------------------------------+------------------------
Reporter: Behoston | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 4.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------+------------------------
I'm trying to do something weird, but I found an interesting bug:


{{{
#!div style="font-size: 100%"
Example:
{{{#!python
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.


{{{
#!div style="font-size: 100%"
Example:
{{{#!python
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

}}}
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33415>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 7, 2022, 1:30:18 AM1/7/22
to django-...@googlegroups.com
#33415: @classproperty breakes @abc.abstractmethod
----------------------------------+--------------------------------------
Reporter: Mateusz Legięcki | Owner: nobody
Type: Bug | Status: closed
Component: Utilities | Version: 4.0
Severity: Normal | Resolution: needsinfo

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => needsinfo


Comment:

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?

--
Ticket URL: <https://code.djangoproject.com/ticket/33415#comment:1>

Reply all
Reply to author
Forward
0 new messages