1

Let's say I have a module CustomClasses.py, which contains 10 classes. I have a method let's say process() which can take an object of any of the classes of the CustomClasses module.

Method:

def process(custom_class_instance):
    some code...

Now, for type hints for custom_class_instance, I can use typing.Union to indicate supported types, but that would definitely take much of the code space (hence reduce readability) and would be some manual work. So is there some other way, with which I can specify that the custom_class_instance would be an object of any of the classes in CustomClasses.py.

Parthesh Soni
  • 133
  • 1
  • 6
  • 4
    Make all classes in CustomClasses.py inherit from one common (abstract) base class which you can hint against…?! – deceze Mar 01 '21 at 07:29

1 Answers1

0

As per @deceze's comment on the question, making all classes inherit from a common abstract base class, and using the base class for type-hint works.

Parthesh Soni
  • 133
  • 1
  • 6