I feel like I'm losing my mind. I was working on a simple project involving a subclass of int, which may not be the best idea, but I need to inherit many of int's magic methods for integer operations.
I added a default argument wraps=True to the class' __init__ method but started getting an unexpected TypeError, where my default argument was being assumed as a keyword argument for int.
The section of the code could be simplified to this:
class MyClass(int):
def __init__(self, a, *args, b=False, **kwargs):
super().__init__(*args, **kwargs)
self.a = a
self.b = b
and for some reason b (or in my case, wraps) was being passed as a keyword argument to int, which of course, didn't work.
After some testing I found that the same problem occurred with str but not with most other classes, which means that, (I'm guessing) the problem arises from inheriting from an immutable class. Am I correct and is there a way around this problem?
Thanks in advance.