Allow kwargs for BaseException.__init__#2760
Conversation
|
I'm at a loss for the failed test, can someone explain what it does? Is this something I broke? |
|
You need to copy |
|
Thanks :) I would have expected the build system to do such copying. |
| __context__: Optional[BaseException] | ||
| __traceback__: Optional[TracebackType] | ||
| def __init__(self, *args: object) -> None: ... | ||
| def __init__(self, *args: object, **kwargs) -> None: ... |
There was a problem hiding this comment.
Can you add : object as the type? We like to keep all arguments typed.
|
I recently updated mypy to the latest version and started facing an issue:
Since it used to work, I tried to figure out what went wrong and I found these two pull requests: One to add kwargs, the second one to remove them. What's the correct behavior? Thanks! |
|
And I merged both of them, that's embarrassing. :) I think removing them is right: BaseException really does not take kwargs |
|
I agree with @JelleZijlstra. Can you give examples of code that is wrongly flagged by mypy without this patch? The example from python/mypy#4183 (referenced from #1704) is actually an example of why keyword arguments should not be allowed: class ValidationError(Exception):
def __init__(self, message: str, log_level: int=logging.ERROR, *args, **kwargs) -> None:
...
super().__init__(message, log_level, *args, **kwargs)Calling ValidationError("", foo=123) # TypeError: ValidationError does not take keyword arguments |
|
I didn't knew BaseException didn't accept kwargs, mypy wasn't showing any errors until I updated it yesterday. If no kwargs is the correct behavior then I'll update my code, I just wanted to point out the conflict between versions, and if you merge this one then the next version will work differently again. |
|
Well, if your code is showing errors for code that's working correctly, there might still be a problem somewhere. Can you share the problematic code, and did you confirm that it does work correctly at runtime? |
|
At least in my case, I mis-interpreted the class and added the kwargs, which was clearly wrong, it hid a mistake in one exception definition we had, so removing them again is certainly correct. |
Exceptions take keyword args, let mypy accept those.