object oriented – Python inheritance: how to check the closest abstract parent class?

I’m dealing with two categories of machine learning algorithms. For simplicity, let’s call them A and B.

There are multiple concrete algorithms in each category, and my goal is to implement all of them. Because of this, my initial plan was to define abstract classes CategoryAAlgorithms and CategoryBAlgorithms, and have each of them define a set of methods that must be implemented by the concrete algorithms. So far so good – these abstract classes serve as a nice template and I find that they make my project a lot more understandable.

However, after I’ve done this, I found that the abstract methods defined in CategoryBAlgorithms contain all the abstract methods defined in CategoryAAlgorithms.

To avoid code duplication, I want to have CategoryBAlgorithms inherit from CategoryAAlgorithms. However, somewhere else in my code I do the following checks:

# just an example
if isinstance(some_instance_of_a_concrete_algorithm, CategoryAAlgorithms):
elif isinstance(some_instance_of_a_concrete_algorithm, CategoryBAlgorithms):

This means that, if I do the inheritance, then for a concrete algorithm from category B, both if statements would be true.

Is there a way for me to get around this issue? My initial thought was to check for the closest abstract parent, but I don’t think this is a clean solution, so I welcome other ideas.

Thanks in advance.