Abstract Base Classes are non-instantiable classes used to define the expected behaviour of subclasses.
Questions tagged [abc]
280 questions
0
votes
2 answers
10 sites through same codebase django MTI, ABCs or EAV
I have a django based web shop that has been evolving over the past year. Currently there's about 8 country specific shops running through the same code base, plus an API, and there's soon to be a B2B website, and a few more countries to add to the…

user307927
- 748
- 9
- 22
0
votes
1 answer
how to inherit and enforce an abstract method defined in a superclass with __metaclass__ = ABCMeta
There is class A (in another package) that defines an abstract method my_abstract_method() using the old way of defining an abstract class by setting __metaclass__ = ABCMeta.
My class B is a subclass of A, and I would like B to inherit A's…

morfys
- 2,195
- 3
- 28
- 35
0
votes
1 answer
Abstract class, repeated inheritance, specific example
I am working on a codebase that I don't entirely master (yet). I have the following 3-class stucture:
class Processor(ABC):
@abstractmethod
def process(self, *args: Any, **kwargs: Any):
pass
class AbstractEsTask(Processor, ABC):
…

hartmut
- 934
- 12
- 25
0
votes
2 answers
How to define two identical classes with different method parameter names?
I'm developing a scientific library where I would define vector functions in the time and frequency domain (linked by FFT). I created a class for vector formulas in the freq domain, and now I'd want to define an identical class for the time…

Neinstein
- 958
- 2
- 11
- 31
0
votes
2 answers
Manipulating function docstring and signature in base class
I have an abstract base class Base that provides an abstract method _run() that needs to be implemented by derived classes, as well as a method run() that will call _run() and do some extra work that is common to all derived classes.
In all derived…

jhansen
- 1,096
- 1
- 8
- 17
0
votes
1 answer
Understanding Abstract Base Classes in Python
I was reading about abstract base class and came across https://www.python-course.eu/python3_abstract_classes.php website. I got general idea about them but I found two statement contradictory of each other.
Subclasses of an abstract class in…

Pratik
- 1,351
- 1
- 20
- 37
0
votes
1 answer
Verifying that an object instance complies with ABC in Python
I have an API that receives a serialized representation of an object that I expect to comply with a particular interface (known at development time). The serialized data I receive includes details that are used to create implementations of the…

SlyCaptainFlint
- 501
- 1
- 4
- 12
0
votes
1 answer
Python : Using abc in Python < 2.6
Do someone know an implementation of abc for older versions of Python (older than 2.6) ?
EDIT : I am for example looking for a snippet that would do the same thing as ABCMeta and abstractmethod, with same interface, I actually need to make a piece…

sebpiq
- 7,540
- 9
- 52
- 69
0
votes
1 answer
How do I create a class level property in an abstract base class (Python 3+) that I want derived classes to define?
Is there a standard way for creating class level variables in an abstract base class (ABC) that we want derived classes to define?
I could implement this with properties as follows:
from abc import ABC
from abc import abstractmethod
class…

Gaurav Keswani
- 431
- 4
- 14
0
votes
0 answers
Python abstract method inside implemented base class method
I'm able to authenticate against some RESTful API with one of the following methods:
password
certificate
anonymous
I've created AuthenticationBase class and its…

user3719188
- 590
- 5
- 7
0
votes
0 answers
Making a class abstract the old way wont work
I am trying to create an abstract base class.
When using the syntax of python 3, it work perfectly.
But then when I switch to the syntax of python 2.7 it just wont work.
the following code is written in 2.7 syntax, and if I run it, it will work,…

Max
- 907
- 2
- 13
- 27
0
votes
1 answer
Python checking type of list elements
I'm trying use ABC and...
Checking type of single parameter is quite straithforward:
def spam_method(param):
if not isinstance(param, SpamInterface):
raise TypeError
It looks good. In first line of method definition is mentioned what type I…

Maciej Wawrzyńczuk
- 860
- 1
- 8
- 19
0
votes
1 answer
Python 3 ignores metaclass directive?
Edited
I have 2 classes inheriting from ABC, and a third class inheriting from both, each in a different file. Tried to provide the metaclass of ABCMeta to the last class, to resolve the conflict of metaclasses, but it fails with the same…

Vitaliy
- 291
- 1
- 14
0
votes
0 answers
Need suggestions for fixing ABC error?
I'm creating a boid flocking simulator and getting some errors. Suspecting they are issued by wrong usage of ABC. But I can't fix the error, been trying for a day.
the primary issue is in the Check_input class. flyers is somehow undefined and I'm…

Arcane
- 1
- 1
0
votes
1 answer
Why does this mypy, slots, and abstract class hack work?
I've got a relatively big Python project and in an effort to minimise debugging time I'm trying to emulate a few aspects of a lower-level language. Specifically
Ability to type cast (Static Typing)
Prevent dynamic attribute addition to classes.…

m4p85r
- 402
- 2
- 17