-
Notifications
You must be signed in to change notification settings - Fork 115
b042: ignore overloaded init, ignore if str+pickle dunder, improve README #531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| import typing | ||
| from typing import overload | ||
|
|
||
|
|
||
| class MyError_no_args(Exception): | ||
| def __init__(self): # safe | ||
| ... | ||
|
|
@@ -46,6 +50,25 @@ class MyError_posonlyargs(Exception): | |
| def __init__(self, x, /, y): | ||
| super().__init__(x, y) | ||
|
|
||
| # ignore overloaded __init__ | ||
| class MyException(Exception): | ||
| @overload | ||
| def __init__(self, x: int): ... | ||
| @overload | ||
| def __init__(self, x: float): ... | ||
|
Comment on lines
+53
to
+58
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've tested this branch and confirmed that it resolves the false positive I posted in #525.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks Kurt! |
||
|
|
||
| def __init__(self, x): | ||
| super().__init__(x) | ||
|
|
||
| class MyException2(Exception): | ||
| @typing.overload | ||
| def __init__(self, x: int): ... | ||
| @typing.overload | ||
| def __init__(self, x: float): ... | ||
|
|
||
| def __init__(self, x): | ||
| super().__init__(x) | ||
|
|
||
| # triggers if class name ends with, or | ||
| # if it inherits from a class whose name ends with, any of | ||
| # 'Error', 'Exception', 'ExceptionGroup', 'Warning', 'ExceptionGroup' | ||
|
|
@@ -70,5 +93,23 @@ def __init__(self, x): ... # B042: 4 | |
| class ExceptionHandler(Anything): | ||
| def __init__(self, x): ... # safe | ||
|
|
||
| class FooException: | ||
| class FooException: # safe, doesn't inherit from anything | ||
| def __init__(self, x): ... | ||
|
|
||
| ### Ignore classes that define __str__ + any pickle dunder | ||
| class HasReduceStr(Exception): | ||
| def __reduce__(self): ... | ||
| def __str__(self): ... | ||
| def __init__(self, x): ... | ||
|
|
||
| class HasReduce(Exception): | ||
| def __reduce__(self): ... | ||
| def __init__(self, x): ... # B042: 4 | ||
| class HasStr(Exception): | ||
| def __str__(self): ... | ||
| def __init__(self, x): ... # B042: 4 | ||
|
|
||
| class HasStrReduceEx(Exception): | ||
| def __reduce_ex__(self, protocol): ... | ||
| def __str__(self): ... | ||
| def __init__(self, x): ... | ||
Uh oh!
There was an error while loading. Please reload this page.