Problem
Imagine I have a base class, e.g. TreeNode
with several subclasses
deriving from it, possibly with more instance fields (like children for inner nodes). What are current best practices to check against the
concrete class Type. I may have something like NumericNode
and CharacterNode
and a function that accepts both.
Solutions
One possibility would be of course to use isinstance()
but I
think this is rather unpythonic. Another solution (which I would
like to avoid as much as possible) is to use something like a class
constant per subclass and then check against it. This would be similar to the first solution.
Or should I encapsulate the isinstance() solution into a dedicated function that hides the real typechecking?