If the requirement that it be a property is flexible, you could just define a static abstract method:

class X:
  @staticmethod
  @abstractmethod
  def var():
    pass

class Y(X):
  @staticmethod
  def var():
    return [1, 2]

>>> Y.var()
[1, 2]
Answer from Ben Caine on Stack Overflow
🌐
Python
docs.python.org › 3 › library › abc.html
abc — Abstract Base Classes
A subclass of the built-in staticmethod(), indicating an abstract staticmethod. Otherwise it is similar to abstractmethod(). This special case is deprecated, as the staticmethod() decorator is now correctly identified as abstract when applied to an abstract method:
🌐
Python.org
discuss.python.org › ideas
Provide a canonical way to declare an abstract class variable - Ideas - Discussions on Python.org
October 28, 2024 - There’s a recent help post of Abstract variables in abc that asks about how an “abstract variable” can be declared such that it is required for a subclass to override the variable, to which @drmason13 replied: Although this approach of abusing an abstract property as an abstract variable ...
🌐
Ikriv
ikriv.com › blog
Python: the land of abstract static methods – Ivan Krivyakov
from abc import abstractmethod, ABC class A(ABC): @staticmethod @abstractmethod def static_method(): print("A.static_method()") A.static_method() # prints A.static_method() obj = A() # raises TypeError: Can't instantiate abstract class A # without an implementation for abstract method 'static_method' In Python, @abstractmethod is a decorator, not a keyword.
🌐
Medium
medium.com › nerd-for-tech › python-instance-vs-static-vs-class-vs-abstract-methods-1952a5c77d9d
Python: Instance vs Static vs Class vs Abstract Methods | by DhineshSunder Ganapathi | Nerd For Tech | Medium
April 4, 2021 - Abstract methods are created using the @abstractmethod decorator. They override the properties of base class. I hope this article gives the gist in understanding different types methods in Python OOPS inventory, Do share your thoughts in comments.
🌐
DZone
dzone.com › coding › languages › the definitive guide on how to use static, class or abstract methods in python
The Definitive Guide on How to Use Static, Class or Abstract Methods in Python
August 21, 2013 - Therefore, you can't force an implementation of your abstract method to be a regular, class or static method, and arguably you shouldn't. Starting with Python 3 (this won't work as you would expect in Python 2, see issue 5867), it's now possible to use the @staticmethod and @classmethod decorators on top of @abstractmethod:
Find elsewhere
🌐
Tudelft
forum.kavli.tudelft.nl › programming questions
Abstract properties in Python's abstract base classes: good practices - Programming questions - Kavli institute discussions
July 30, 2020 - Question about software architecture. Below there is a snip from kwant’s system.py and its InfiniteSystem class, but it is not specific. I think that implicit definition of abstract properties in mixin/abstract classes is a bad coding practice, confusing for reading the code and when trying to use these mixins in practice (bonus points for confusing my static code analyzer).
Top answer
1 of 13
182

Python 3.3+

from abc import ABCMeta, abstractmethod


class A(metaclass=ABCMeta):
    def __init__(self):
        # ...
        pass

    @property
    @abstractmethod
    def a(self):
        pass

    @abstractmethod
    def b(self):
        pass


class B(A):
    a = 1

    def b(self):
        pass

Failure to declare a or b in the derived class B will raise a TypeError such as:

TypeError: Can't instantiate abstract class B with abstract methods a

Python 2.7

There is an @abstractproperty decorator for this:

from abc import ABCMeta, abstractmethod, abstractproperty


class A:
    __metaclass__ = ABCMeta

    def __init__(self):
        # ...
        pass

    @abstractproperty
    def a(self):
        pass

    @abstractmethod
    def b(self):
        pass


class B(A):
    a = 1

    def b(self):
        pass
2 of 13
126

Since this question was originally asked, python has changed how abstract classes are implemented. I have used a slightly different approach using the abc.ABC formalism in python 3.6. Here I define the constant as a property which must be defined in each subclass.

from abc import ABC, abstractmethod


class Base(ABC):

    @classmethod
    @property
    @abstractmethod
    def CONSTANT(cls):
        raise NotImplementedError

    def print_constant(self):
        print(type(self).CONSTANT)


class Derived(Base):
    CONSTANT = 42

This forces the derived class to define the constant, or else a TypeError exception will be raised when you try to instantiate the subclass. When you want to use the constant for any functionality implemented in the abstract class, you must access the subclass constant by type(self).CONSTANT instead of just CONSTANT, since the value is undefined in the base class.

There are other ways to implement this, but I like this syntax as it seems to me the most plain and obvious for the reader.

The previous answers all touched useful points, but I feel the accepted answer does not directly answer the question because

  • The question asks for implementation in an abstract class, but the accepted answer does not follow the abstract formalism.
  • The question asks that implementation is enforced. I would argue that enforcement is stricter in this answer because it causes a runtime error when the subclass is instantiated if CONSTANT is not defined. The accepted answer allows the object to be instantiated and only throws an error when CONSTANT is accessed, making the enforcement less strict.

This is not to fault the original answers. Major changes to the abstract class syntax have occurred since they were posted, which in this case allow a neater and more functional implementation.

🌐
GitHub
github.com › cython › cython › issues › 2651
Combining @staticmethod and @abc.abstractmethod fails at runtime · Issue #2651 · cython/cython
According to https://docs.python.org/3/library/abc.html#abc.abstractmethod this is legal, as long as the @staticmethod decorator comes first. If I remove the @abstractmethod annotation, I can cythonize and import the module.
Author   ghost
🌐
Python.org
discuss.python.org › ideas
[abc] Add abstract attributes via `abstract` type-hint - Ideas - Discussions on Python.org
April 24, 2023 - Feature or enhancement Add a special generic type hint abstract, that allows specifying that subclasses must implement an attribute. from abc import ABC, abstract class Foo(ABC): myattr: abstract[int] # 100 upvotes) How to create abstract properties in python a...
🌐
GitHub
github.com › python › cpython › issues › 101605
Static abstract method link is not enforced while calling a class · Issue #101605 · python/cpython
February 6, 2023 - from abc import ABC, abstractmethod class Parent(ABC): @staticmethod @abstractmethod def method1(): pass @staticmethod @abstractmethod def method2(): print("Method 2 in Parent") @abstractmethod def method3(self): pass @abstractmethod def method4(self): print("Method 4 in Parent") class Child(Parent): @staticmethod def method2(): print("Method 2 in Child") def method4(self): print("Method 4 in Child") def test_abstract_class(): Parent.method1() # Should complain because calling an abstract class should be forbidden Parent.method2() # Should complain because calling an abstract class should be f
Author   pmithrandir
🌐
Python Module of the Week
pymotw.com › 3 › abc
abc — Abstract Base Classes
The Base class in the example cannot be instantiated because it has only an abstract version of the property getter methods for value and constant. The value property is given a concrete getter in Implementation and constant is defined using a class attribute. $ python3 abc_abstractproperty.py ERROR: Can't instantiate abstract class Base with abstract methods constant, value Implementation.value : concrete property Implementation.constant: set by a class attribute
🌐
OMKAR PATHAK
omkarpathak.in › 2018 › 09 › 15 › python-static-class-abstract
Demystifying Python OOP (Part 3) - Python Static, Class and Abstract methods | OMKAR PATHAK
September 15, 2018 - class Example(object): @staticmethod def just_another_method(): print('This is static method') example = Example() example.just_another_method() # This is static method · Abstract methods in Python are pretty much different than class methods and static methods.
🌐
The Teclado Blog
blog.teclado.com › python-abc-abstract-base-classes
How to Write Cleaner Python Code Using Abstract Classes
October 26, 2022 - We use @abstractmethod to define a method in the abstract base class and combination of @property and @abstractmethod in order to define an abstract property. I hope you learnt something new today! If you're looking to upgrade your Python skills even further, check out our Complete Python Course. ... What are @classmethod and @staticmethod?
🌐
GeeksforGeeks
geeksforgeeks.org › python › abstract-classes-in-python
Abstract Classes in Python - GeeksforGeeks
These properties are declared with the @property decorator and marked as abstract using @abstractmethod.
Published   September 3, 2025
Top answer
1 of 1
8

You can't do what you want with just ABCMeta. ABC enforcement doesn't do any type checking, only the presence of an attribute with the correct name is enforced.

Take for example:

>>> from abc import ABCMeta, abstractmethod, abstractproperty
>>> class Abstract(object):
...     __metaclass__ = ABCMeta
...     @abstractmethod
...     def foo(self): pass
...     @abstractproperty
...     def bar(self): pass
... 
>>> class Concrete(Abstract):
...     foo = 'bar'
...     bar = 'baz'
... 
>>> Concrete()
<__main__.Concrete object at 0x104b4df90>

I was able to construct Concrete() even though both foo and bar are simple attributes.

The ABCMeta metaclass only tracks how many objects are left with the __isabstractmethod__ attribute being true; when creating a class from the metaclass (ABCMeta.__new__ is called) the cls.__abstractmethods__ attribute is then set to a frozenset object with all the names that are still abstract.

type.__new__ then tests for that frozenset and throws a TypeError if you try to create an instance.

You'd have to produce your own __new__ method here; subclass ABCMeta and add type checking in a new __new__ method. That method should look for __abstractmethods__ sets on the base classes, find the corresponding objects with the __isabstractmethod__ attribute in the MRO, then does typechecking on the current class attributes.

This'd mean that you'd throw the exception when defining the class, not an instance, however. For that to work you'd add a __call__ method to your ABCMeta subclass and have that throw the exception based on information gathered by your own __new__ method about what types were wrong; a similar two-stage process as what ABCMeta and type.__new__ do at the moment. Alternatively, update the __abstractmethods__ set on the class to add any names that were implemented but with the wrong type and leave it to type.__new__ to throw the exception.

The following implementation takes that last tack; add names back to __abstractmethods__ if the implemented type doesn't match (using a mapping):

from types import FunctionType

class ABCMetaTypeCheck(ABCMeta):
    _typemap = {  # map abstract type to expected implementation type
        abstractproperty: property,
        abstractstatic: staticmethod,
        # abstractmethods return function objects
        FunctionType: FunctionType,
    }
    def __new__(mcls, name, bases, namespace):
        cls = super(ABCMetaTypeCheck, mcls).__new__(mcls, name, bases, namespace)
        wrong_type = set()
        seen = set()
        abstractmethods = cls.__abstractmethods__
        for base in bases:
            for name in getattr(base, "__abstractmethods__", set()):
                if name in seen or name in abstractmethods:
                    continue  # still abstract or later overridden
                value = base.__dict__.get(name)  # bypass descriptors
                if getattr(value, "__isabstractmethod__", False):
                    seen.add(name)
                    expected = mcls._typemap[type(value)]
                    if not isinstance(namespace[name], expected):
                        wrong_type.add(name)
        if wrong_type:
            cls.__abstractmethods__ = abstractmethods | frozenset(wrong_type)
        return cls

With this metaclass you get your expected output:

>>> class Abstract(object):
...     __metaclass__ = ABCMetaTypeCheck
...     @abstractmethod
...     def foo(self): pass
...     @abstractproperty
...     def bar(self): pass
...     @abstractstatic
...     def baz(): pass
... 
>>> class ConcreteWrong(Abstract):
...     foo = 'bar'
...     bar = 'baz'
...     baz = 'spam'
... 
>>> ConcreteWrong()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Can't instantiate abstract class ConcreteWrong with abstract methods bar, baz, foo
>>> 
>>> class ConcreteCorrect(Abstract):
...     def foo(self): return 'bar'
...     @property
...     def bar(self): return 'baz'
...     @staticmethod
...     def baz(): return  'spam'
... 
>>> ConcreteCorrect()
<__main__.ConcreteCorrect object at 0x104ce1d10>
🌐
GitHub
github.com › python › mypy › issues › 4426
Should we always prohibit "abstract" attributes? · Issue #4426 · python/mypy
November 19, 2017 - Currently, instantiating explicit subclasses of protocols with "abstract" attributes is prohibited: class P(Protocol): x: int # Note, no r.h.s. class C(P): pass class D(P): def __init__(self) -> None: self.x = 42 C() # E: Cannot instanti...
Author   ilevkivskyi
🌐
Peaku
peaku.co › questions › 14323-python:-crea-una-propiedad-estatica-abstracta-dentro-de-la-clase
Python: Create Abstract Static Property within Class - PeakU
class X(metaclass=abc.ABCMeta): @staticmethod @property @abc.abstractmethod def var(): return [1,2] class Y(X): @staticmethod @property def var(): return X.var + [3,4] The static method will work, but the property will not function as intended: y=Y(); y.var returns the property itself, <property at 0x2c16aa1b3b8>. This answer is close to what's desired, but it doesn't work in this case since the base class, X, will already have a var attribute (so subclass can access via super). How do you define a python class to have an abstract, static attribute/property?