Trying to add hints to this:
class ValidationError(Exception):
def __init__(self, message: str, log_level: int=logging.ERROR, *args, **kwargs) -> None:
self.message = message
self.log_level = log_level
super().__init__(message, log_level, *args, **kwargs)
gives:
error: Too many arguments for "__init__" of "BaseException"
Well, Exception.__init__ supposedly takes *args, **kwargs so how can this ever have "too many arguments"?
If I change my code to:
class ValidationError(Exception):
def __init__(self, message: str, log_level: int=logging.ERROR) -> None:
self.message = message
self.log_level = log_level
super().__init__(message, log_level)
then no error reported.
I'm actually happy with this change to my code. But does it suggest an issue with mypy?
This also works:
class ValidationError(Exception):
def __init__(self, message: str, log_level: int=logging.ERROR, whatever: str='WTF') -> None:
self.message = message
self.log_level = log_level
super().__init__(message, log_level, whatever)
So it seems the issue is not with any specific number of arguments, but of mypy not understanding that *args means 'any number'?
Trying to add hints to this:
gives:
Well,
Exception.__init__supposedly takes*args, **kwargsso how can this ever have "too many arguments"?If I change my code to:
then no error reported.
I'm actually happy with this change to my code. But does it suggest an issue with mypy?
This also works:
So it seems the issue is not with any specific number of arguments, but of mypy not understanding that
*argsmeans 'any number'?