Starting with Python 3.3, it is possible to combine @staticmethod and @abstractmethod, so none of the other suggestions are necessary anymore:

@staticmethod
@abstractmethod
def my_abstract_staticmethod(...):

@abstractstaticmethod has been deprecated since version 3.3 (but is still there in Python 3.14).

Answer from gerrit on Stack Overflow
🌐
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.
🌐
Python
docs.python.org › 3 › library › abc.html
abc — Abstract Base Classes
A subclass of the built-in staticmethod(), indicating an abstract staticmethod.
🌐
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 - An abstract method is a method that has a declaration but does not have an implementation. While we are designing large functional units, we use an abstract class. An abstract class can be considered as a blueprint for other classes.
🌐
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 ...
🌐
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
🌐
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 - Abstract methods in Python are the methods that are defined in the base class, but do not have any implementation. The derived class must override these abstract methods in their definition.
🌐
Zhengwenjie
zhengwenjie.net › python-methods
A style guide to static, class, and abstract methods in Python 2.X and 3.X
Python’s abstract methods are like C++’s pure virtual functions: they define methods that must be implemented in the subclasses, and classes containing abstract methods (aka abstract classes) cannot be instantiated.
Find elsewhere
🌐
Medium
medium.com › top-python-libraries › python-difference-between-abstractmethod-and-staticmethod-4bd3764eaf95
Python — Difference between abstractmethod and staticmethod | by Vinoth Kumar | Top Python Libraries | Medium
December 5, 2024 - If a subclass does not implement an abstract method, it cannot be instantiated. ... Promotes reuse and flexibility. Forces implementation in the derived classes. ... Python is widely used in fields such as data analysis, machine learning, and web development.
🌐
Reddit
reddit.com › r/learnjava › can't declare a method as abstract static. is there a workaround or best practice?
r/learnjava on Reddit: Can't declare a method as abstract static. Is there a workaround or best practice?
May 9, 2024 -

I created an abstract method that uses no instance data in any of its implementations, so I wanted to make it static to avoid the need to instantiate the subclass and help me to reuse the code elsewhere.

boolean canSeeSquareFrom(int x, int y, int initX, int initY) {
    return 2 == Math.abs((x - initX) * (y - initY));
}

Then I found out static methods can't be overridden.

I have to override the method to use polymorphism when I'm calling the method on objects, so what do I do? Does Java support a way to call a non-static method without creating unnecessary instances?

(i have a workaround I don't like, which is creating an instance of the subclass every time I need the method; is this the best we can do?)

Knight.getKnight().canSeeSquareFrom(0, 0, 2, 1);

Edit: regarding the automod, I also looked up all of the non-access modifiers and didn't see any that were helpful from what I could tell. (I was hoping I misunderstood something there)

Game.java:101: error: non-static method canSeeSquareFrom(int,int,int,int) cannot be referenced from a static context
        Knight/*.getKnight()*/.canSeeSquareFrom(0, 0, 2, 1);
                              ^
Top answer
1 of 5
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full - best also formatted as code block You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2 of 5
1
Move the method to a separate class, ideally in a package holding the rest of your utility functions that should be public and static (do not relate to an instance, only operate on given parameters)
🌐
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 › typing
Calling abstract methods - Typing - Discussions on Python.org
January 6, 2024 - PEP 544 indicates that a type checker should generate an error if a class that explicitly derives from the protocol attempts to call a method through super() if that method is unimplemented in the protocol. class Proto(Protocol): def method(self) -> None: ... class Impl(Proto): def method(self) -> None: super().method() # Type checker error This makes sense because the method in the protocol is effectively abstract.
🌐
Pynerds
pynerds.com › abstract-classes-in-python
Abstract classes in Python
October 16, 2024 - Static methods are utility methods, they cannot access object or class data.Tthey are defined using the @staticmethod decorator and can be accessed from the class itself or from instances.
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>
🌐
Learnscript
learnscript.net › en › python › classes › abstract-classes
Introduction to Python Abstract Classes and Abstract Methods; Define and Implement Python Abstract Classes and Abstract Methods - Python Tutorial | Learn
In Python abstract base classes or their derived classes, you can use the @abstractmethod decorator provided by the abc module to define abstract methods or abstract attributes that are essentially methods. The @abstractmethod decorator can be used in conjunction with other decorators (@classmethod, @staticmethod...
🌐
Real Python
realpython.com › instance-class-and-static-methods-demystified
Python's Instance, Class, and Static Methods Demystified – Real Python
March 17, 2025 - Abstract you say? Don’t worry—it involves runnable code, and it’s there to set the stage for a more practical example later on. ... To get warmed up, you’ll write a small Python file called demo.py with a bare-bones Python class that contains stripped-down examples of all three method types:
🌐
Thenerdnook
thenerdnook.io › p › static-and-abstract-methods
Python Decoded: Deep Dive into Static and Abstract Methods for Programmers
February 27, 2024 - Dive deep into Python's static and abstract methods. Unlock code mastery with our comprehensive guide. Python Decoded: Your ultimate resource.
🌐
Dive into Python
diveintopython.org › home › learn python programming › classes in python › class methods and properties
Class Methods in Python: Public, Protected, Private, Static, Abstract
May 3, 2024 - An abstract class method is a method that is declared but contains no implementation. It is used as a template for other methods that are defined in a subclass. A class method is a method that is bound to the class and not the instance of the class. It can be accessed using the class name. A static method is a method that is bound to the class and not the instance of the class...
🌐
Medium
medium.com › fundamentals-of-artificial-intellegence › understanding-abstractmethod-and-staticmethod-in-python-37fff24bb98e
Understanding @abstractmethod and @staticmethod in Python | by Arts2Survive | Fundamentals of Artificial Intelligence | Medium
May 14, 2025 - It’s used with an @ symbol before a method name. The @abstractmethod decorator is used when you're working with abstract classes in Python. An abstract class is like a blueprint for other classes.