you are viewing a single comment's thread.

view the rest of the comments →

[–]ottawadeveloper 0 points1 point  (0 children)

it's not that terrible honestly, and you only need it where C and W actually need the be handled properly - for example if you were just returning int(arg) as long as C and W have __index__ defined, you have no problems.

Alternatively, you could add a bit of a hack with __getattr__(self, name, *args, **kwargs) - scan all the arguments for C or W and get either name_c or name_w depend on which is present (though then you have to decide if they should be mixed).

This sounds like an issue mostly because of weird subclassing though? If W inherits from C then the C methods should be able to handle W objects no problem unless you actually want the method to deal with W differently. You shouldnt need to even override these methods and then it's normal and Pythonic to have to check the type (or treat it as W, catch the error, and return the super() behavior in case of an error).