Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combination of @classmethod @property and @abc.abstractmethod #93167

Open
jbaudisch opened this issue May 24, 2022 · 0 comments
Open

Combination of @classmethod @property and @abc.abstractmethod #93167

jbaudisch opened this issue May 24, 2022 · 0 comments
Assignees
Labels
type-bug

Comments

@jbaudisch
Copy link

@jbaudisch jbaudisch commented May 24, 2022

Bug report

import abc

class A(abc.ABC):
    @classmethod
    @property
    @abc.abstractmethod
    def type(cls):
        raise NotImplementedError
    
class B(A, metaclass=abc.ABCMeta):
    @abc.abstractmethod
    def other(self):
        raise NotImplementedError
    
class C(B):
    @classmethod
    @property
    def type(cls):
        return 'C'

    def other(self):
        print('other')

c = C()
c.other()

This script is failing with an NotImplementedError:

Traceback (most recent call last):
  File "C:\Users\Justin Baudisch\Desktop\test.py", line 10, in <module>
    class B(A, metaclass=abc.ABCMeta):
  File "C:\Program Files\Python310\lib\abc.py", line 107, in __new__
    _abc_init(cls)
  File "C:\Users\Justin Baudisch\Desktop\test.py", line 8, in type
    raise NotImplementedError
NotImplementedError

So the script executes the "type"-property. But why? This is not the expected behaviour (?).
If I remove the @property decorator and leave it as a method, it works fine. Same when I remove the @classmethod decorator.

Your environment

  • CPython versions tested on: Python 3.10
  • Operating system and architecture: Windows 11
@jbaudisch jbaudisch added the type-bug label May 24, 2022
@rhettinger rhettinger self-assigned this May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug
Projects
None yet
Development

No branches or pull requests

2 participants