Abstract Base Classes are non-instantiable classes used to define the expected behaviour of subclasses.
Questions tagged [abc]
280 questions
1
vote
1 answer
Overriding the decorator of an abstract class in the inherited class
So here's what I have:
The abstract class:
class DataWrapper(object):
def decorator(f):
def preprocess(*args, **kwargs):
return f(*args, **kwargs)
return preprocess
@decorator
def datamethod1(self, ..): ...
…

user1769889
- 175
- 1
- 1
- 8
1
vote
1 answer
Why am I able to instantiate my Abstract Base Class in Python?
As I understand it, I can use the abc module in Python to create abstract classes that can't be instantiated (amongst other nice properties). I tried to use this to create a hierarchy of Exception classes to represent various exit codes for my…

Andrew Ferrier
- 16,664
- 13
- 47
- 76
1
vote
1 answer
Is it possible to craft a Python dict with all (or most) of the properties of a dict with Abstract Base Classes?
I am familiar with the concept of Abstract Base Classes (ABC's), as providing sets of properties of the builtin objects, but I don't have really any experience working with them. I can see that there's a Mapping ABC, and a MutableMapping that…

Russia Must Remove Putin
- 374,368
- 89
- 403
- 331
1
vote
5 answers
Inherited class "invalid pointer error" when calling virtual functions
As you can see in the code below, I have an Abstract Base Class "HostWindow", and class that derives from it "Chrome". All the functions are implemented in Chrome. The issue is, I can't call functions in Chrome if they're virtual.
class HostWindow :…

Alex MacCaw
- 984
- 1
- 6
- 19
1
vote
0 answers
collections.MutableSequence subclass appears to be singleton?
Possible Duplicate:
“Least Astonishment” in Python: The Mutable Default Argument
Playing around with code found in this answer, I found the following weirdness. Here's my class declaration, a totally trivial MutableSequence subclass:
import…

Andrew Roberts
- 770
- 2
- 8
- 13
1
vote
1 answer
Python ABC seems to allow incomplete implementation
I'm trying to create base class and force all subclasses to implement it's interface. I'm using the abc module for this purpose.
Here is the base class:
class PluginBase:
__metaclass = abc.ABCMeta
@abc.abstractmethod
def strrep(self):
…

tonytony
- 1,994
- 3
- 20
- 27
0
votes
1 answer
How do I call python subclassed methods from superclass methods?
I have the following kind of superclass / subclass setup:
class SuperClass(object):
def __init__(self):
self.do_something() # requires the do_something method always be called
def do_something(self):
raise…

Eyal
- 1,094
- 10
- 16
0
votes
1 answer
Python, __init__ method of abstract class implicitly being called?
I'm not too familiar with the use of abstract classes, so I'm trying to understand what is happening in some code I'm using at the moment.
In the code, I have a base dataset class, and some implementations of datasets inheriting from the main one,…

Carlo
- 1,321
- 12
- 37
0
votes
1 answer
The implementation of Sequence interface is not sufficient to be a Sequence
I've noticed that duck typing works reasonably well up to a certain point in checking whether a class is an instance of an abstract class.
For example, to be an instance of collections.abc.Sized, we only need to define a __len__() method:
import…

Ali
- 206
- 1
- 4
0
votes
0 answers
How to inherit __iter__ from a ABC subclass through a router class?
I am trying to make a MVC framework with routing. The model itself is iterable.
If I don't use a router class then it will give all the first keys from the model.
But when using the router class, I get the following error: TypeError: 'ABCMeta'…

Typnix
- 1
- 1
0
votes
1 answer
How can I have a child class implement only a specific property with the base class have it's base methods use the abstract property?
Trying an implementation where a base abstract class implements several properties (building some paths). With specific implementations having specific parts of the paths.
See a simplified example below. I have tried this with abstract properties,…

mrc
- 126
- 1
- 11
0
votes
0 answers
Is there a way to explicitly declare an argument as an array in Python?
Is there a way to explicitly state an argument to a function in python should be an array of some custom class?
i.e.
I can write the following function to enforce the type of the args
def foo_bar(foo: str, bar: int):
print("foo bar stuff")
But…

user21113865
- 99
- 7
0
votes
1 answer
Make sure abstract method would be a coroutine when implemented
First of all, I'm aware it is developers' responsibility to make sure your define your method as a coroutine when implementing child class
class MyBase(ABC):
@abstractclassmethod
def the_coroutine(self):
"""
I want this to be…

GopherM
- 352
- 2
- 8
0
votes
2 answers
Cannot import the attribute from "abc.py" in Python
I have hello() in test/abc.py as shown below:
# "test/abc.py"
def hello():
return "Hello"
Then, I import and call hello() from abc.py in test/main.py as shown below:
# "test/main.py"
from abc import hello
print(hello())
But, I got the error…

Super Kai - Kazuya Ito
- 22,221
- 10
- 124
- 129
0
votes
0 answers
Why am I getting the error 'class FidelityPromo(Promotion):IndentationError: expected an indented block'?
from abc import ABC, abstractmethod
from collections import namedtuple
Customer = namedtuple('Customer', 'name fidelity')
class LineItem:
def __init__(self, product, quantity, price):
self.product = product
self.quantity =…