-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
PR: Remove mutable defaults for keyword arguments #23293
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work on this @gb119!
providers = [] if providers is None else providers | ||
super().__init__(plugin, parent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
providers = [] if providers is None else providers | |
super().__init__(plugin, parent) | |
super().__init__(plugin, parent) | |
providers = [] if providers is None else providers |
Our custom is not add code before calling super
unless it's really necessary.
max_line_count=300, exitfunc=None, profile=False, | ||
multithreaded=True): | ||
commands = [] if commands is None else commands |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this to be at line 171 below.
file_associations = ( | ||
{} if file_associations is None else file_associations | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move these to be at line 321 below.
external_path_history = ( | ||
[] if external_path_history is None else external_path_history | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move these to be at line 77 below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this can just be removed as there is already a test for an empty list that works equally well for None
data = [] if data is None else data | ||
QAbstractTableModel.__init__(self, parent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data = [] if data is None else data | |
QAbstractTableModel.__init__(self, parent) | |
QAbstractTableModel.__init__(self, parent) | |
data = [] if data is None else data |
""" | ||
Run Python script in a separate process | ||
package=None -> module is in sys.path (standard library modules) | ||
""" | ||
args = [] if args is None else args | ||
p_args = [] if p_args is None else p_args | ||
assert module is not None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert module is not None | |
assert module is not None |
For code clarity.
"""Create action to run a GUI based Python script""" | ||
args = [] if args else args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
args = [] if args else args | |
args = [] if args is None else args |
It seems missing.
@@ -116,7 +116,8 @@ def __init__(self, parent, handle_links=True, class_parent=None): | |||
self.setPage(web_page) | |||
self.source_text = '' | |||
|
|||
def setup(self, options={}): | |||
def setup(self, options=None): | |||
options = {} if options is None else options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
options = {} if options is None else options | |
options = {} if options is None else options | |
For clarity.
Description of Changes
Whilst tracking down an odd race condition in locating conda, I spotted several instances where a mutable type
was being used as a default for a keyword argument. This PR simple replaces the mutable constant (typically [] and {})
with a
None
and then does anx = [] if x is None else x
or equivalent on the first line of each affected function.It is possible that functionality was depending on the default mutable value being changed by a function call, but
I'd argue that it is sufficiently non-obvious that doing that should be considered a bug :-)
Issue(s) Resolved
Partially Fixes #23061
Affirmation
By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.
I certify the above statement is true and correct: gb119 (https://github.com/gb119)