Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7610657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:28:12+00:00 2026-05-31T01:28:12+00:00

I have an Abstract Base Class and subclasses defined as follows (Python 2.7): import

  • 0

I have an Abstract Base Class and subclasses defined as follows (Python 2.7):

import abc
import MyDatabaseModule

class _DbObject(object):
    __metaclass__ = abc.ABCMeta

    def _GetObjectType(self):
        raise NotImplementedError, "Please override in the derived class"

    ObjectType = abc.abstractproperty(_GetObjectType, None)

class Entry(_DbObject):
    _objectTypeID = 'ENTRY'

    def _GetObjectType(self):
        return MyDatabaseModule.DoesSomethingWith(self._objectTypeID)

    ObjectType = property(_GetObjectType, None)

This works fine, meaning that the base class _DbObject cannot be instantiated because it has only an abstract version of the property getter method.

try:
    dbObject = _DbObject()
    print "dbObject.ObjectType: " + dbObject.ObjectType
except Exception, err:
    print 'ERROR:', str(err) 

Now I can do:

entry = Entry()
print entry.ObjectType

to get access to the ObjectType property. However, what I would like to be able to do is just:

print Entry.ObjectType

However, wherever I try to insert @classmethod, I get the error classmethod object is not callabale.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:28:13+00:00Added an answer on May 31, 2026 at 1:28 am

    So, the magic for the way “property” works in Python is implemented using the descriptor protocol – property itself if a powerful built-in that provides a descriptor that works well for instances, not classes as you had seen.

    So, you need a “class property” – the property built-in can’t give you that, but the descriptor protocol can. What the descriptor protocol says is that whenever an attribute is retrieved from the class, if it is an object with a __get__ method, that method is called with “self, instance, owner” – and if it is retrieved from the class, instead of from an instance, the “instance” parameter is set to None.

    BTW, as stated by @Constantinius, this does not have to do with the ABC’s at all, just with you wanting a “class property”.

    class classproperty(object):
        def __init__(self, func):
            self.func = func
        def __get__(self, instance, owner):
            return self.func(owner)
    
    
    class Entry(_DbObject):
        _objectTypeID = 'ENTRY'
    
        def _GetObjectType(cls):
            return MyDatabaseModule.DoesSomethingWith(cls._objectTypeID)
        ObjectType = classproperty(_GetObjectType, None)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined an abstract method in my base class to take in a
I have an abstract entity base class defined like this: public abstract class SessionItem
I have an abstract base-class to enforce some subclasses to overload the << operator.
I have an abstract base class called Person with subclasses Employee and Customer. How
I have a base class that has an abstract getType() method. I want subclasses
I have the following base class: abstract class Base { public abstract object Var
I have an abstract base class which acts as an interface. I have two
I have an abstract base class with a TcpClient field: public abstract class ControllerBase
I have an abstract base class and derived class: type TInterfaceMethod = class public
I have an abstract base class and I want to declare a field or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.