import abc
from typing import ClassVar

from pydantic import BaseModel
from devtools import debug

class Fruit(BaseModel, abc.ABC):
    @property
    @abc.abstractmethod
    def type(self) -> str:
        """The name of the type of fruit."""

class Apple(Fruit):
    type: ClassVar[str] = "apple"
    size: int

a = Apple(size=4)
debug(a, a.type)

Unless you want to allow type to be changed when creating a model instance, in which case just make it a field on Fruit.

🌐
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…
🌐
W3Schools
w3schools.com › python › python_classes.asp
Python Classes
Almost everything in Python is an object, with its properties and methods. A Class is like an object constructor, or a "blueprint" for creating objects.
Discussions

[abc] Add abstract attributes via `abstract` type-hint - Ideas - Discussions on Python.org
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... More on discuss.python.org
🌐 discuss.python.org
8
April 24, 2023
How to create abstract properties in python abstract classes? - Stack Overflow
I want all the classes that inherit from Base to provide the name property, so I made this property an @abstractmethod. Then I created a subclass of Base, called Base_1, which is meant to supply some functionality, but still remain abstract. There is no name property in Base_1, but nevertheless python ... More on stackoverflow.com
🌐 stackoverflow.com
Enforcing Abstract Property in Python Classes - TestMu AI Community
How to create Python abstract property in abstract classes? In the following code, I created a base abstract class Base. I want all the classes inheriting from Base to provide the name property, so I made it an @abstractmethod. Then, I created a subclass of Base, called Base1, which is meant ... More on community.testmuai.com
🌐 community.testmuai.com
0
January 9, 2025
Access abstract class property from class method
When accessing a class property from a class method mypy does not respect the property decorator. Steps to reproduce: class Example: @property @classmethod def name(cls) -> str: return "my_... More on github.com
🌐 github.com
14
January 15, 2020
People also ask

What is an abstract class in Python?
An abstract class in Python is a class that cannot be instantiated directly. It can include abstract methods that any subclass must implement.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › abstract class in python
Abstract Class in Python | With Example and Interface Comparison
Can an abstract class have properties in Python?
Yes, an abstract class in Python example can have abstract properties, which must be implemented by the subclass, just like abstract methods.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › abstract class in python
Abstract Class in Python | With Example and Interface Comparison
Can we instantiate an abstract class in Python?
No, you cannot instantiate an abstract class in Python example directly. It must be inherited, and its abstract methods must be implemented before instantiation.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › abstract class in python
Abstract Class in Python | With Example and Interface Comparison
🌐
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...
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › abstract class in python
Abstract Class in Python | With Example and Interface Comparison
September 12, 2024 - Abstract properties improve code organization by forcing subclasses to define specific attributes. This can be helpful in large systems where different subclasses are expected to adhere to a common interface.
Find elsewhere
🌐
Python
docs.python.org › 3 › library › abc.html
abc — Abstract Base Classes
This special case is deprecated, as the property() decorator is now correctly identified as abstract when applied to an abstract method: class C(ABC): @property @abstractmethod def my_abstract_property(self): ...
🌐
TestMu AI Community
community.testmuai.com › ask a question
Enforcing Abstract Property in Python Classes - TestMu AI Community
January 9, 2025 - How to create Python abstract property in abstract classes? In the following code, I created a base abstract class Base. I want all the classes inheriting from Base to provide the name property, so I made it an @abstractmethod. Then, I created a subclass of Base, called Base1, which is meant ...
🌐
GitHub
github.com › python › mypy › issues › 8532
Access abstract class property from class method · Issue #8532 · python/mypy
January 15, 2020 - class Example: @property @classmethod def name(cls) -> str: return "my_name" def name_length_from_method(self) -> int: return len(self.name) # succeeds @classmethod def name_length_from_class_method(cls) -> int: return len(cls.name) # error: Argument 1 to "len" has incompatible type "Callable[[], str]"
Author   olirice
🌐
Scaler
scaler.com › home › topics › abstract class in python
Abstract Class in Python - Scaler Topics
April 9, 2024 - As we have been told, properties are used in Python for getters and setters. Abstract property is provided by the abc module to force the child class to provide getters and setters for a variable in Python.
🌐
Python Course
python-course.eu › oop › the-abc-of-abstract-base-classes.php
20. The 'ABC' of Abstract Base Classes | OOP | python-course.eu
Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation.
🌐
DataCamp
datacamp.com › tutorial › python-abstract-classes
Python Abstract Classes: A Comprehensive Guide with Examples | DataCamp
January 22, 2025 - To guarantee that every subclass provides its implementation, abstract properties can be specified using the @property decorator in combination with @abstractmethod. When creating classes that need read-only or computed attributes that are essential to the class's operation, this method is especially helpful.
🌐
Python.org
discuss.python.org › python help
Why does using property and abstractmethod not enforce properties in child? - Python Help - Discussions on Python.org
October 14, 2021 - Example: from abc import ABC, abstractmethod class AbstractExample(ABC): @property @abstractmethod def some_prop(self): pass class ConcreteExample(AbstractExample): def some_prop(self): return None c = ConcreteExample() # this does not raise
🌐
Real Python
realpython.com › ref › glossary › abstract-base-class
abstract base class (ABC) | Python Glossary – Real Python
In Python, an abstract base class (ABC) is a class that can’t be instantiated on its own and is designed to be a blueprint for other classes, allowing you to define a common interface for a group of related classes.
🌐
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 ...
🌐
Pydantic
docs.pydantic.dev › latest › concepts › models
Models - Pydantic Validation
Besides, using these abstract types can also lead to poor validation performance, and in general using concrete container types will avoid unnecessary checks. By default, Pydantic models won't error when you provide extra data, and these values will simply be ignored: from pydantic import BaseModel class Model(BaseModel): x: int m = Model(x=1, y='a') assert m.model_dump() == {'x': 1}
🌐
GeeksforGeeks
geeksforgeeks.org › python › data-abstraction-in-python
Data Abstraction in Python - GeeksforGeeks
It is implemented and does not need to be overridden by Dog class. Abstract properties work like abstract methods but are used for properties. These properties are declared with @property decorator and marked as abstract using @abstractmethod.
Published   January 22, 2026
🌐
GeeksforGeeks
geeksforgeeks.org › python › abstract-classes-in-python
Abstract Classes in Python - GeeksforGeeks
The Dog class implements the species property, making it a concrete subclass that can be instantiated. Abstract properties enforce that a subclass provides the property’s implementation.
Published   September 3, 2025