You have a class called baseTest within a module called baseTest, so after importing the module baseTest, you would need to use baseTest.baseTest to access the class:
baseTest.baseTest.register(concreteTest)
Note that you don't even need to register concreteTest as a virtual subclass, since it's already an actual subclass. The register() method is meant to register classes that don't actually derive from an abstract class you defined, but do fulfill the interface.
That said, it is unlikely that you routinely want to use abstract classes in Python. They are useful in some special circumstances, but aren't used as the standard way of declaring interfaces. See also the blog post Python is not Java.
Answer from Sven Marnach on Stack OverflowPython
docs.python.org › 3 › library › abc.html
abc — Abstract Base Classes
An ABC can be subclassed directly, and then acts as a mix-in class. You can also register unrelated concrete classes (even built-in classes) and unrelated ABCs as “virtual subclasses” – these and their descendants will be considered subclasses of the registering ABC by the built-in issubclass() function, but the registering ABC won’t show up in their MRO (Method Resolution Order) nor will method implementations defined by the registering ABC be callable (not even via super()).
Videos
15:31
Protocols vs ABCs in Python - When to Use Which One? - YouTube
10:05
Python Interfaces and Abstract Base Class (ABC): A Must-Know for ...
02:12
Python's ABC (Abstract Base Class) in 2 Minutes - YouTube
21:27
Understanding Python: Abstract Base Classes - YouTube
00:51
The Python ABC's.. Abstract Base Class! #python #programming #coding ...
05:11
Python abstract base class (ABC) example - YouTube
GitHub
github.com › python › cpython › blob › main › Lib › abc.py
cpython/Lib/abc.py at main · python/cpython
Use this metaclass to create an ABC. An ABC can be subclassed · directly, and then acts as a mix-in class. You can also register · unrelated concrete classes (even built-in classes) and unrelated · ABCs as 'virtual ...
Author python
Python Module of the Week
pymotw.com › 2 › abc
abc – Abstract Base Classes - Python Module of the Week
In this example the PluginImplementation is not derived from PluginBase, but is registered as implementing the PluginBase API. $ python abc_register.py Subclass: True Instance: True
Python.org
discuss.python.org › ideas
List all registered classes from `abc.ABC.register` - Ideas - Discussions on Python.org
September 28, 2022 - Currently, as far as I know, there’s no way to recover the registered subclasses of abc.ABC (through cls.register(MyClass)) class A: pass class Array(abc.ABC): pass Array.register(A) # How to recover A from Array after this call ? assert isinstance(A(), Array) abc.get_registered(Array) # == [A] #
W3Schools
w3schools.com › python › ref_module_abc.asp
Python abc Module
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... from abc import ABC, abstractmethod class Shape(ABC): @abstractmethod def area(self): pass class Square(Shape): def __init__(self, s): self.s = s def area(self): return self.s * self.s sq = Square(3) print(isinstance(sq, Shape)) print(sq.area()) Try it Yourself »
Readthedocs
docspy3zh.readthedocs.io › en › latest › library › abc.html
27.7. abc — Abstract Base Classes — Python 3 文档(简体中文) 3.2.2 documentation
An ABC can be subclassed directly, and then acts as a mix-in class. You can also register unrelated concrete classes (even built-in classes) and unrelated ABCs as “virtual subclasses” – these and their descendants will be considered subclasses of the registering ABC by the built-in issubclass() function, but the registering ABC won’t show up in their MRO (Method Resolution Order) nor will method implementations defined by the registering ABC be callable (not even via super()).
Medium
elfi-y.medium.com › inheritance-in-python-with-abstract-base-class-abc-5e3b8e910e5e
Inheritance in Python with Abstract Base Class(ABC) | by E.Y. | Medium
January 13, 2021 - This method is one step further to register , as it defines whether the registered subclass is considered a subclass of this ABC. So you can customise the behaviour of issubclass without the need to call register() on every subclass. The important bit here is that it’s defined as classmethod on the class and it's called by abc.ABC.__subclasscheck__.
Readthedocs
python-can.readthedocs.io › en › 3.1.1 › _modules › abc.html
abc — python-can 3.1.0 documentation
""" def __new__(mcls, name, bases, namespace, **kwargs): cls = super().__new__(mcls, name, bases, namespace, **kwargs) _abc_init(cls) return cls def register(cls, subclass): """Register a virtual subclass of an ABC. Returns the subclass, to allow usage as a class decorator.
Python Course
python-course.eu › oop › the-abc-of-abstract-base-classes.php
20. The 'ABC' of Abstract Base Classes | OOP | python-course.eu
from abc import ABC, abstractmethod class AbstractClassExample(ABC): def __init__(self, value): self.value = value super().__init__() @abstractmethod def do_something(self): pass
Python Module of the Week
pymotw.com › 3 › abc › index.html
abc — Abstract Base Classes
$ python3 abc_abc_base.py Subclass: True Instance: True · Another benefit of subclassing directly from the abstract base class is that the subclass cannot be instantiated unless it fully implements the abstract portion of the API. ... import abc from abc_base import PluginBase @PluginBase.register class IncompleteImplementation(PluginBase): def save(self, output, data): return output.write(data) if __name__ == '__main__': print('Subclass:', issubclass(IncompleteImplementation, PluginBase)) print('Instance:', isinstance(IncompleteImplementation(), PluginBase))
Python
docs.python.org › 3.8 › library › abc.html
abc — Abstract Base Classes — Python 3.8.20 documentation
An ABC can be subclassed directly, and then acts as a mix-in class. You can also register unrelated concrete classes (even built-in classes) and unrelated ABCs as “virtual subclasses” – these and their descendants will be considered subclasses of the registering ABC by the built-in issubclass() function, but the registering ABC won’t show up in their MRO (Method Resolution Order) nor will method implementations defined by the registering ABC be callable (not even via super()).
Python
docs.python.org › 3.10 › library › abc.html
abc — Abstract Base Classes — Python 3.10.18 documentation
An ABC can be subclassed directly, and then acts as a mix-in class. You can also register unrelated concrete classes (even built-in classes) and unrelated ABCs as “virtual subclasses” – these and their descendants will be considered subclasses of the registering ABC by the built-in issubclass() function, but the registering ABC won’t show up in their MRO (Method Resolution Order) nor will method implementations defined by the registering ABC be callable (not even via super()).
Machine Learning Plus
machinelearningplus.com › python › python-abcs-the-complete-guide-to-abstract-base-classes
Python ABCs- The Complete Guide to Abstract Base Classes – Machine Learning Plus
Let’s create a Printer abstract base class with a print_document() method, then create classes that we’ll register as virtual subclasses. ... class Printer(ABC): @abstractmethod def print_document(self, document): pass # Different printer classes (imagine they're from different libraries) class LaserPrinter: def print_document(self, document): return f"Laser printer: {document}" class InkjetPrinter: def print_document(self, document): return f"Inkjet printer: {document}" # Register classes as virtual subclasses Printer.register(LaserPrinter) Printer.register(InkjetPrinter) # Now we can check if they're subclasses laser = LaserPrinter() inkjet = InkjetPrinter() print(f"Is LaserPrinter a subclass of Printer?
GitHub
github.com › python › mypy › issues › 2922
ABCMeta.register support · Issue #2922 · python/mypy
September 7, 2016 - class A(metaclass=abc.ABCMeta): pass class B: pass A.register(B) a: A = B() # currently E: Incompatible types in assignment (expression has type "B", variable has type "A") print(isinstance(a, A)) # -> True Mypy could support cases like ...
Author miedzinski