0

I'm working on an existing project adding some new features and came across this issue:

from abc import ABC

class Preprocessor(ABC):
    @classmethod
    @property
    def name(self):
        raise NotImplementedError

    @classmethod
    @property
    def version(self):
        raise NotImplementedError

    @classmethod
    @property
    def feature_group_name(cls):
        return f'{cls.name}_{cls.version}'
    
class Feature(Preprocessor):
    name = 'testFeature'
    version = 'v1'

Feature().feature_group_name

The result I'm expecting should be:

'testFeature_v1'

But I'm getting something like:

<bound method ? of <class '__main__.Feature'>>

Thank you in advance

  • What version of python are you using? From here https://stackoverflow.com/questions/128573/using-property-on-classmethods it appears that you need to use python >= 3.9 to get the functionality you're trying to use. – defladamouse Dec 02 '21 at 19:52
  • 1
    Does this answer your question? [Using property() on classmethods](https://stackoverflow.com/questions/128573/using-property-on-classmethods) – defladamouse Dec 02 '21 at 19:52
  • Do you really want `name` et al. to be *class*-level properties, or just regular properties that are accessed via an instance of the class? – chepner Dec 02 '21 at 20:26
  • What is the problem you are trying to solve here? Can you give us a clear description of the intent of this code? – C.Nivs Dec 02 '21 at 20:58
  • @defladamouse I was able to fix this by updating to python 3.9. Thank you – Leandro Acosta Dec 03 '21 at 19:19

0 Answers0