Questions tagged [abc]

Abstract Base Classes are non-instantiable classes used to define the expected behaviour of subclasses.

280 questions
0
votes
0 answers

Check if instance is of object extending an ABC

The structure I have looks like this: Parent(abc.ABCMeta) -> Foo(Parent) Parent(abc.ABCMeta) -> SubParent(abc.ABCMeta, Parent) -> Bar(SubParent) Then, say we have instances like so, x = Foo() t = Bar() From this design, is it possible to answer…
Debosmit Ray
  • 5,228
  • 2
  • 27
  • 43
0
votes
2 answers

python abc subclasshook has no effect when class is derived

There is no way to return False from issubclass when class is derived from class with __subclashook__ implementation. I modified code from: python subclasscheck & subclasshook I only added '(Sized)' to both class definitions: from abc import…
PiotrB
  • 133
  • 1
  • 10
0
votes
1 answer

Abstract Property on __name__ not enforced

Consider the following sample code: from abc import ABC, abstractmethod, abstractproperty class Base(ABC): @abstractmethod def foo(self) -> str: print("abstract") @property @abstractmethod def __name__(self) -> str: …
Keozon
  • 998
  • 10
  • 25
0
votes
0 answers

python: isinstance(value, Sequence[Real])

Python's typing module allows containers of specific object types to be described, such as Sequence[numbers.Real]. However, the container interfaces in collections.abc do not accept such parameters, so I can only check isinstance(value,…
blue_note
  • 27,712
  • 9
  • 72
  • 90
0
votes
1 answer

Updating Classes that inherit from abstract classes

I have an abstract class ship. from abc import ABC, abstractmethod class ship(ABC): def __init__(self): ... @abstractmethod def do_stuff(self,stuff,things): pass I have multiple classes that inherit from it…
David
  • 89
  • 9
0
votes
1 answer

running ABC inside YOSYS returns ' Warning: Detected 1 multi-output gates'

When using YOSYS I call abc command: abc -liberty mycells3.lib mycells3.lib is a simple custom technology library based on the example library provided in YOSYS distribution where I added ADDER cell (named FAX1): library(demo) { cell(BUF)…
0
votes
1 answer

Define private variable of class as abstract

I want to know what is the correct way to make my class's private variables as abstract. Let me summarize the properties of my variable: Class variable private abstract Structure of my classes is like: from abc import ABCMeta class…
Moinuddin Quadri
  • 46,825
  • 13
  • 96
  • 126
0
votes
1 answer

Child classes implement a MooseX::Interface with MooseX::ABC (Abstract Base Class)

I am trying to force all child classes of an Abstract Base Class to implement an interface. When I try add with '' to the ABC, it requires me to implement the required methods immediately and add sub {} for each interface…
0
votes
1 answer

Python 2.7 -- Calling an Abstract Base Class' method from an Instance

I am searching for the proper way to call an abstract base class' method from an instance of a class that is registered as a subclass of the ABC. This is some very basic test code to first figure out how to make this work. This is where I am…
user4766915
0
votes
0 answers

Calling subclass method (overridden abstract class method) from abstract class method in python

I would like to call the overridden abstract class method (subclass method) from the abstract class method, but getting several errors. Could you help me, please? My concept: import abc from my_module import Format, Message class…
Petr Krampl
  • 816
  • 9
  • 11
0
votes
1 answer

How to write a Python ABC with a concrete initializer in python 2.6 to 3.5?

The Context I have a python application with a relatively involved class hierarchy. It needs to work with python 2.6 up to python 3.5 (a big range, I know!), and I've been having particular problems with ABCs. I'm using the six library's…
sirosen
  • 1,716
  • 13
  • 17
0
votes
1 answer

Can I unregister a class as an `Iterator`?

I've been handed code with a class that incorrectly subclasses the abstract base class collections.Iterator. It doesn't follow the Iterator contract and this flawed inheritance relationship causes issues downstream. Is there any way to unregister…
MRocklin
  • 55,641
  • 23
  • 163
  • 235
0
votes
1 answer

Duck-typable classes, ABC, iheritance, __new__

I'm writing a test system that uses, amongst other things, a data source. When running, it will read a bunch of instruments, but for testing and development of the back end, I want it to read a file, or return random numbers. In the future, I know…
Neil_UK
  • 1,043
  • 12
  • 25
0
votes
2 answers

How to use Abstract Base Classes in Python?

Following this tutorial I'm trying to use Abstract Base Classes in Python. So I constructed two files: basis.py: import abc class PluginBase(object): __metaclass__ = abc.ABCMeta @abc.abstractmethod def load(self, input): …
kramer65
  • 50,427
  • 120
  • 308
  • 488
0
votes
0 answers

Distinguish abstract base class from implementation

Developing a metaclass that provides self-registration of subclasses (somewhat similar to this idea), I came across the following problem: Given a class that may be either an abstract base class or an implementation of one, how do I distinguish…
Emilia Bopp
  • 866
  • 10
  • 20
1 2 3
18
19