Abstract Base Classes are non-instantiable classes used to define the expected behaviour of subclasses.
Questions tagged [abc]
280 questions
1
vote
1 answer
How to convert abc file to a musicxml file using music21?
I'm writing my thesis and I need some help to understand how I can convert using music21 a set of abc files to a set of musicxml files. I need to write a automatic stream that helps me to convert all the notthingam dataset into a set of musicxml…

Davide Lionetti
- 11
- 2
1
vote
1 answer
Python: enforcing abstract method
I have written the follow code to demonstrate abstract methods that must be implemented by its subclasses. I read that when a method in a parent class is decorated as abstract, its subclass must implement it otherwise it cannot be instantiated.…

Ziqi
- 2,445
- 5
- 38
- 65
1
vote
1 answer
Assertion in abstract base class?
Essentially what I want is to require that subclasses of an abstract base classes not only implement certain attributes or methods, but can also make requirements on those, such as data types or allowed values.
For example, let's say I want to…

user3059201
- 775
- 2
- 7
- 11
1
vote
1 answer
Python ABC classes: One of multiple methods has to be overridden
In Python, I have an abstract base class which has four methods, of which at least one has to be overwritten. Is it possible to somehow implement this with the @abstractmethod decorator or something similar?
Here is a stripped down version of the…

LSchueler
- 1,414
- 12
- 23
1
vote
1 answer
python: Overwrite only some methods from AbstractClass
What is the pythonic way to have an intermediate class that overwrites some of the method’s from an Abstract parent, but not all. Must it also overwrite methods it does not wish to change?
class Animal(six.with_metaclass(ABCMeta, object)):):
…

Sam Shleifer
- 1,716
- 2
- 18
- 29
1
vote
1 answer
Why no character/codepoint string equivalant of `collections.abc.ByteString`?
Python's collections.abc module offers Sequence and MutableSequence abstract base classes (ABCs) and these cover¹ the str, bytes, bytearray and similar types as expected.
collections.abc also offers a ByteString ABC, which covers bytes, bytearray…

cjs
- 25,752
- 9
- 89
- 101
1
vote
0 answers
Implement child class level variable in abstract base class
I have made an abstract base class using metaclass=ABCMeta to implement some default methods and properties that all its derived classes should have, something like this:
class BaseClass(metaclass=ABCMeta):
def __init__(self):
…

MTV DNA
- 187
- 7
1
vote
1 answer
Python abstract base classes
As I dig further into Python internals, I start to see abc's more often in the documentation. Unfortunately the docs don't explain how they can be used. I haven't even been able to use the "concrete implementations" of these abstract base classes.…

Ben_Z
- 19
- 3
1
vote
0 answers
How to make ABC work with Boost.Python/C++ Classes?
I want abc.abstractmethod to work on the following class:
from abc import ABC
from my_cpp_module import my_class
class A(my_class, ABC):
@abstractmethod
def implement_me(self, arg):
'''not implemented'''
class B(A):
pass
b =…

frans
- 8,868
- 11
- 58
- 132
1
vote
0 answers
Python: Non-abstract methods in an Abstract Base Class
I'm implementing a meta class as follows:
from abc import ABCMeta
class Algorithm(metaclass=ABCMeta):
# lots of @abstractmethods
# Non-abstract method
@property
def name(self):
''' Name of the algorithm '''
return…

MarcinKonowalczyk
- 2,577
- 4
- 20
- 26
1
vote
0 answers
Why can't Python properties and property-setters be inherited?
My class hierarchy looks like:
- Foo_ABC # abstract base class
- Baz_ABC # abstract base class
- Baz1
- Baz2
- Bar
...
Baz_ABC defines an abstractproperty thing, but also implements the setter @thing.setter because the code is…

BoltzmannBrain
- 5,082
- 11
- 46
- 79
1
vote
0 answers
typing.NamedTuple, abc.NamedTuple mixins in python 3.6.2?
I am new to python (3.6.2 is the version I am using).
I am currently porting (trying to port) a DSL implementation from Scala to python for some projet in which python is imposed.
So I am looking for a way to efficiently write immutable class…

remi
- 566
- 3
- 13
1
vote
6 answers
What do *you* use C++ ABC constructors for?
What do people here use C++ Abstract Base Class constructors for in the field? I am talking about pure interface classes having no data members and no non-pure virtual members.
Can anyone demonstrate any idioms which use ABC constructors in a…

nly
- 179
- 7
1
vote
1 answer
Can I write abc.ABC without resorting to metaclasses in Python 3.6?
Python 3.6 added PEP 487, which adds an __init_subclass__ method among other things. Is it possible to write a version of ABC that doesn't use a metaclass?

Neil G
- 32,138
- 39
- 156
- 257
1
vote
2 answers
Python metaclass (abc module) inheritance with nested classes
I've written a Python 3 metaclass containing a nested metaclass (with abc), like:
class A_M(object, metaclass=abc.ABCMeta):
class A_nested_M(object, metaclass=abc.ABCMeta):
def ... # some methods
Now, implementing like
class A(A_M):
…

norb
- 77
- 1
- 10