Are you using python3 to run that code? If yes, you should know that declaring metaclass in python3 have changes you should do it like this instead:

import abc

class AbstractClass(metaclass=abc.ABCMeta):

  @abc.abstractmethod
  def abstractMethod(self):
      return

The full code and the explanation behind the answer is:

import abc

class AbstractClass(metaclass=abc.ABCMeta):

    @abc.abstractmethod
    def abstractMethod(self):
        return

class ConcreteClass(AbstractClass):

    def __init__(self):
        self.me = "me"

# Will get a TypeError without the following two lines:
#   def abstractMethod(self):
#       return 0

c = ConcreteClass()
c.abstractMethod()

If abstractMethod is not defined for ConcreteClass, the following exception will be raised when running the above code: TypeError: Can't instantiate abstract class ConcreteClass with abstract methods abstractMethod

Answer from mouad on Stack Overflow
🌐
Python
docs.python.org › 3 › library › abc.html
abc — Abstract Base Classes
A class that has a metaclass derived ... the normal ‘super’ call mechanisms. abstractmethod() may be used to declare abstract methods for properties and descriptors....
🌐
Reddit
reddit.com › r/learnpython › what's the point of abc & @abstractmethod
r/learnpython on Reddit: What's the point of ABC & @abstractmethod
July 27, 2021 -

Hello. In this first example, I have a short and straightforward code w/ a class for interface. It doesn't inherit from ABC and doesn't have any abstract methods.

class Abs():
    def __init__(self, name, age):
        self.name = name
        self.age = age
        
    def go_to(self):
        return f"{self.name} is going to {self.place}."
        
class Teacher(Abs):
    place = "work"

class Student(Abs):
    place = "school"
    
t1 = Teacher("James", 56)
s1 = Student("Tim", 15)

print(t1.go_to())
print(s1.go_to())

In this second example, it's the exact opposite.

from abc import ABC, abstractmethod

class Abs(ABC):
    def __init__(self, name, age):
        self.name = name
        self.age = age
        
    @abstractmethod
    def go_to(self):
        ...
        
class Teacher(Abs):
    place = "work"
    
    def go_to(self):
        return f"{self.name} is going to {self.place}."

class Student(Abs):
    place = "school"
    
    def go_to(self):
        return f"{self.name} is going to {self.place}."
    
t1 = Teacher("James", 56)
s1 = Student("Tim", 15)

print(t1.go_to())
print(s1.go_to())

Both examples have the same output. In the tutorials/articles I've read, most times the second example is preferred. In the abstract class, abstract methods get defined and decorated, and then in the inheriting classes they all get redefined with the rest of the logic. What's the point of creating a class w/ abstract methods which later on we redefine? What issue does that solve? Why not just proceed as in the first example - simple, less code, one parent class for the interface, if we need to add other details, we do so in the base class once and handle the extra logic with that additional info there. Doesn't the first code present a better example of loose coupling - just one connection between parent and child classes, where in the second code, we get connections between parent/child in every method that we redefine? I feel like I'm missing something, because to me, the second example is much more spaghetti-like. If anyone can explain why it's a good practice to redefine abstract methods that would be nice. Also, is it a bad practice to write code as in the first example, w/o ABC+@abstractmethod in the parent class?
Thanks.

Top answer
1 of 5
10
So your examples are a bit problematic because you would never use @abstractmethod in that situation. In your example there is no reason not to define the function only in the parent class--the parent knows everything it needs in order to execute the function, and the children don't change the execution at all. Also, Abs is a terrible name for a class. @abstractmethod is for when you: Require all children to have a method Don't have enough information to define that method in the parent Essentially, it "requires" child classes to define this method. This allows you to include the method in your parent interface so you can document it but raises a sensible error if the child doesn't re-define it. This is mostly useful for parent classes that will never have direct instances--only instances of subclasses. Consider designing a shooter game like Doom or Quake. You might represent various objects and enemies as class instances. To keep the game synced, every clock tick all the objects need to "update" themselves. Enemies might move around, lights might blink, and items might recharge. They all need to do something, but what they do is completely unique to each class. In a case like this, you might define the update() method in the parent Object class. This is mostly a convenience feature--you can write the same code perfectly well without it. However, it allows you to refer to all objects collectively (isinstance(o, Object)) through the parent class, and still ensure that update() exists, even though the parent doesn't know what to do with it. You could easily define update() in the parent and have it do nothing, but this prevents errors from being raised if you call this on a child class that hasn't re-defined the method.
2 of 5
3
let's imagine a List interface - we'll have the operations of append and pop class List(ABC): @abstractmethod def append(self, val): pass @abstractmethod def pop(self): pass now we could create class LinkedList(List) and class ArrayList(List) where we'd implement the methods for both of the list types the reason for using ABC and @abstractmethod is because it doesn't make sense to be able to be able to instantiate a List - that doesn't have an implementation. it only describes what behaviour an implementation should have to provide. think of it as providing a contract by which all users of an object know what behaviour to expect abstract classes and methods are more useful in languages such as java where you can't rely on duck typing void doThing(List list) this would take any subclass of List and be checked at compile time to have the expected methods of append and pop
Discussions

python - I used `__metaclass__` to set up `abc.ABCMeta` as the metaclass, but unimplemented `@abstractmethod`s still fail to raise an exception. Why? - Stack Overflow
I have read python docs about abstract base classes: From here: abc.abstractmethod(function) A decorator indicating abstract methods. Using this decorator requires that the class’s metacl... More on stackoverflow.com
🌐 stackoverflow.com
What's the point of ABC & @abstractmethod
So your examples are a bit problematic because you would never use @abstractmethod in that situation. In your example there is no reason not to define the function only in the parent class--the parent knows everything it needs in order to execute the function, and the children don't change the execution at all. Also, Abs is a terrible name for a class. @abstractmethod is for when you: Require all children to have a method Don't have enough information to define that method in the parent Essentially, it "requires" child classes to define this method. This allows you to include the method in your parent interface so you can document it but raises a sensible error if the child doesn't re-define it. This is mostly useful for parent classes that will never have direct instances--only instances of subclasses. Consider designing a shooter game like Doom or Quake. You might represent various objects and enemies as class instances. To keep the game synced, every clock tick all the objects need to "update" themselves. Enemies might move around, lights might blink, and items might recharge. They all need to do something, but what they do is completely unique to each class. In a case like this, you might define the update() method in the parent Object class. This is mostly a convenience feature--you can write the same code perfectly well without it. However, it allows you to refer to all objects collectively (isinstance(o, Object)) through the parent class, and still ensure that update() exists, even though the parent doesn't know what to do with it. You could easily define update() in the parent and have it do nothing, but this prevents errors from being raised if you call this on a child class that hasn't re-defined the method. More on reddit.com
🌐 r/learnpython
11
14
July 27, 2021
Why TypeError instead of NotImplementedError?
Inheriting from Animal does not automatically inherit the methods defined in animal. It tells Python that your class must provide their own implementations of all those methods. By making Animal an abstract base class you are saying "there should never be any Animal objects, only objects of classes which inherit from Animal". In addition to that, intentionally not implementing a method which you are required to implement is generally something you want to avoid. If your class cannot reasonably implement that function, it should not be a subclass of Animal at all. When you say "Dog is a subclass of Animal" you are saying "Dog can do at least everything Animal can". More on reddit.com
🌐 r/learnpython
2
1
December 1, 2023
Is there a such thing as declaring an attribute of an abstract class in Python?
You can do this with @property and @abstractmethod Py:3.3+ (@abstractproperty for earlier versions of python): from abc import ABC, abstractmethod class Base(ABC): @property @abstractmethod def name(self): pass class Concrete(Base): def __init__(self, name): self._name = name @property def name(self): return self._name In []: Base() Out[]: --------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In [56], line 1 ----> 1 Base() TypeError: Can't instantiate abstract class Base with abstract method name In []: Concrete("Name").name Out[]: 'Name' More on reddit.com
🌐 r/learnpython
24
9
February 8, 2023
🌐
GeeksforGeeks
geeksforgeeks.org › python › abstract-classes-in-python
Abstract Classes in Python - GeeksforGeeks
Python provides the abc module to define ABCs and enforce the implementation of abstract methods in subclasses. Example: This example shows an abstract class Animal with an abstract method sound() and a concrete subclass Dog that implements it.
Published   September 3, 2025
🌐
DataCamp
datacamp.com › tutorial › python-abstract-classes
Python Abstract Classes: A Comprehensive Guide with Examples | DataCamp
January 22, 2025 - The class is abstract and cannot be instantiated directly, as indicated by this inheritance. By acting as blueprints, abstract classes make sure that any concrete subclass abides by a set of rules. You can define abstract methods inside an abstract class by using the abstractmethod decorator.
🌐
Real Python
realpython.com › ref › glossary › abstract-base-class
abstract base class (ABC) | Python Glossary – Real Python
To define an abstract base class, you inherit from abc.ABC and use the @abstractmethod decorator to mark methods that must be implemented by subclasses. Attempting to instantiate an abstract base class or a subclass that hasn’t implemented ...
🌐
W3Schools
w3schools.com › python › ref_module_abc.asp
Python abc Module
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... from abc import ABC, abstractmethod class Shape(ABC): @abstractmethod def area(self): pass class Square(Shape): def __init__(self, s): self.s = s def area(self): return self.s * self.s sq = Square(3) print(isinstance(sq, Shape)) print(sq.area()) Try it Yourself »
🌐
The Teclado Blog
blog.teclado.com › python-abc-abstract-base-classes
How to Write Cleaner Python Code Using Abstract Classes
October 26, 2022 - from abc import ABC, abstractmethod # abc is a builtin module, we have to import ABC and abstractmethod class Animal(ABC): # Inherit from ABC(Abstract base class) @abstractmethod # Decorator to define an abstract method def feed(self): pass
Find elsewhere
🌐
Python Course
python-course.eu › oop › the-abc-of-abstract-base-classes.php
20. The 'ABC' of Abstract Base Classes | OOP | python-course.eu
from abc import ABC, abstractmethod class AbstractClassExample(ABC): def __init__(self, value): self.value = value super().__init__() @abstractmethod def do_something(self): pass
🌐
CodeSignal
codesignal.com › learn › courses › revisiting-oop-concepts-in-python › lessons › understanding-abstract-classes-and-abstract-methods-in-python
Understanding Abstract Classes and Abstract Methods in ...
In Python, the abc (Abstract Base Classes) module provides tools for defining abstract base classes. An abstract base class is a class that cannot be instantiated directly and often includes one or more abstract methods. These classes serve as blueprints for other classes, enforcing a consistent ...
🌐
Python
docs.python.org › ja › 3 › library › abc.html
abc --- 抽象基底クラス — Python 3.14.3 ドキュメント
A class that has a metaclass derived ... using any of the normal 'super' call mechanisms. abstractmethod() may be used to declare abstract methods for properties ......
🌐
Qiita
qiita.com › python
PythonのABC - 抽象クラスとダック・タイピング #Go - Qiita
December 8, 2015 - # !/usr/bin/env python # -*- coding: utf-8 -*- from abc import ABCMeta, abstractmethod class Animal(metaclass=ABCMeta): @abstractmethod def sound(self): pass # 抽象クラスを継承しないが、 `sound`メソッドを実装 class Dog(): def sound(self): print("Bow") # 抽象クラスのAnimalへDogを登録 Animal.register(Dog) if __name__ == "__main__": assert issubclass(Dog().__class__, Animal) assert isinstance(Dog(), Animal) 仮想的サブクラスへの登録をすればそのクラスは抽象クラスのものとなりますが、抽象メソッドが実装されていない場合は下記のようにruntimeエラーとなります。(※メソッド呼び出し時) ·
🌐
Medium
leapcell.medium.com › elegant-abstractions-mastering-abstract-base-classes-in-advanced-python-bf3739dd815e
Elegant Abstractions: Mastering ABCs in Advanced Python | by Leapcell | Medium
May 2, 2025 - # Method 1: Directly inherit from ABC from abc import ABC, abstractmethod class LeapCellFileHandler(ABC): @abstractmethod def read(self): pass # Method 2: Use metaclass from abc import ABCMeta, abstractmethod class LeapCellFileHandler(metaclass=ABCMeta): @abstractmethod def read(self): pass · These two methods are equivalent in functionality because the ABC class itself is defined using ABCMeta as the metaclass: class ABC(metaclass=ABCMeta): """Helper class that provides a standard way to create an ABC using inheritance. """ pass · The code is more concise. It is more in line with the principle of simplicity and intuitiveness in Python.
🌐
Python
docs.python.org › ja › 3.13 › library › abc.html
abc --- 抽象基底クラス — Python 3.13.11 ドキュメント
A class that has a metaclass derived ... using any of the normal 'super' call mechanisms. abstractmethod() may be used to declare abstract methods for properties ......