-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
python/typeshed
#1704Description
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'?
Metadata
Metadata
Assignees
Labels
No labels