-
-
Notifications
You must be signed in to change notification settings - Fork 375
python: replace mutable default arguments (W0102) and enable unused wildcard import check (W0614) #6669
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
base: main
Are you sure you want to change the base?
python: replace mutable default arguments (W0102) and enable unused wildcard import check (W0614) #6669
Changes from all commits
78ef2ec
aa0f03b
25dee52
dc6436e
3da5f10
2ce15a0
1e8184a
3d58171
a1400af
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 |
|---|---|---|
|
|
@@ -339,10 +339,10 @@ def test_fatal_error(self, message: str) -> None: | |
| time.sleep(1) | ||
|
|
||
|
|
||
| _MSGR_INSTANCE: Messenger | None = None | ||
|
|
||
|
|
||
| def get_msgr( | ||
| instance=[ | ||
| None, | ||
| ], | ||
| *args, | ||
| **kwargs, | ||
| ) -> Messenger: | ||
|
|
@@ -358,9 +358,10 @@ def get_msgr( | |
| >>> msgr0 is msgr2 | ||
| False | ||
| """ | ||
| if not instance[0]: | ||
| instance[0] = Messenger(*args, **kwargs) | ||
| return instance[0] | ||
| global _MSGR_INSTANCE | ||
| if _MSGR_INSTANCE is None: | ||
| _MSGR_INSTANCE = Messenger(*args, **kwargs) | ||
| return _MSGR_INSTANCE | ||
|
Comment on lines
+361
to
+364
Member
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 don't really like the approach used here. I think it shows well how the previous code was abusing the mutability of the default value, and was affected by it (it was replacing the element at index 0 probably because of that). However, global variables are usually a source of problems, harder to reason correctly about them. Now, is it worse than the dangerous default value, probably not understood? I don't understand extremely well the pygrass message module, so I'd like some help here
Author
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 agree that the global variable approach can introduce complexity, and the previous code’s mutable default was indeed problematic. My intent was to quickly fix the W0102 issue with a straightforward pattern, but I see the benefit of encapsulating this in a class method or decorator for better clarity and maintainability. I can update the code to use a class method singleton or a decorator pattern if that’s preferred.
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 don't have any special insights to it, but I think this is at least more readable than the previous code. The "instance" parameter doesn't seem to be used anywhere, so I think it's fine to get rid of it. |
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.