-
-
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?
Changes from all commits
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 |
---|---|---|
|
@@ -145,9 +145,10 @@ class InternalShell(PythonShellWidget): | |
# TODO: I think this is not being used now? | ||
sig_focus_changed = Signal() | ||
|
||
def __init__(self, parent=None, commands=[], message=None, | ||
def __init__(self, parent=None, commands=None, message=None, | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Please move this to be at line 171 below. |
||
super().__init__(parent, get_conf_path('history_internal.py'), | ||
profile=profile) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -306,7 +306,10 @@ def update_history(self, directory): | |
# Tests | ||
# ============================================================================= | ||
class FileExplorerTest(QWidget): | ||
def __init__(self, directory=None, file_associations={}): | ||
def __init__(self, directory=None, file_associations=None): | ||
file_associations = ( | ||
{} if file_associations is None else file_associations | ||
) | ||
Comment on lines
+310
to
+312
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. Please move these to be at line 321 below. |
||
self.CONF_SECTION = 'explorer' | ||
super().__init__() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,10 @@ class SearchInComboBox(SpyderComboBox): | |
# Signals | ||
sig_redirect_stdio_requested = Signal(bool) | ||
|
||
def __init__(self, external_path_history=[], parent=None, id_=None): | ||
def __init__(self, external_path_history=None, parent=None, id_=None): | ||
external_path_history = ( | ||
[] if external_path_history is None else external_path_history | ||
) | ||
Comment on lines
+48
to
+50
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. Please move these to be at line 77 below. 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. Actually, this can just be removed as there is already a test for an empty list that works equally well for None |
||
super().__init__(parent) | ||
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) | ||
self.setEditable(False) | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -267,7 +267,8 @@ def set_as_code(self, as_code): | |||||||||
|
||||||||||
class PreviewTableModel(QAbstractTableModel): | ||||||||||
"""Import wizard preview table model""" | ||||||||||
def __init__(self, data=[], parent=None): | ||||||||||
def __init__(self, data=None, parent=None): | ||||||||||
data = [] if data is None else data | ||||||||||
QAbstractTableModel.__init__(self, parent) | ||||||||||
Comment on lines
+271
to
272
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.
Suggested change
|
||||||||||
self._data = data | ||||||||||
|
||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -71,7 +71,7 @@ def get_temp_dir(suffix=None): | |||||||
return tempdir | ||||||||
|
||||||||
|
||||||||
def is_program_installed(basename, extra_paths=[]): | ||||||||
def is_program_installed(basename, extra_paths=None): | ||||||||
""" | ||||||||
Return program absolute path if installed in PATH. | ||||||||
Otherwise, return None. | ||||||||
|
@@ -83,6 +83,7 @@ def is_program_installed(basename, extra_paths=[]): | |||||||
|
||||||||
On macOS systems, a .app is considered installed if it exists. | ||||||||
""" | ||||||||
extra_paths = [] if extra_paths is None else extra_paths | ||||||||
home = get_home_dir() | ||||||||
req_paths = [] | ||||||||
if ( | ||||||||
|
@@ -118,13 +119,14 @@ def is_program_installed(basename, extra_paths=[]): | |||||||
return abspath | ||||||||
|
||||||||
|
||||||||
def find_program(basename, extra_paths=[]): | ||||||||
def find_program(basename, extra_paths=None): | ||||||||
""" | ||||||||
Find program in PATH and return absolute path | ||||||||
|
||||||||
Try adding .exe or .bat to basename on Windows platforms | ||||||||
(return None if not found) | ||||||||
""" | ||||||||
extra_paths = [] if extra_paths is None else extra_paths | ||||||||
names = [basename] | ||||||||
if os.name == 'nt': | ||||||||
# Windows platforms | ||||||||
|
@@ -657,11 +659,13 @@ def python_script_exists(package=None, module=None): | |||||||
return path | ||||||||
|
||||||||
|
||||||||
def run_python_script(package=None, module=None, args=[], p_args=[]): | ||||||||
def run_python_script(package=None, module=None, args=None, p_args=None): | ||||||||
""" | ||||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
For code clarity. |
||||||||
assert isinstance(args, (tuple, list)) and isinstance(p_args, (tuple, list)) | ||||||||
path = python_script_exists(package, module) | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -548,8 +548,11 @@ def create_program_action(parent, text, name, icon=None, nt_name=None): | |||||
triggered=lambda: programs.run_program(name)) | ||||||
|
||||||
|
||||||
def create_python_script_action(parent, text, icon, package, module, args=[]): | ||||||
def create_python_script_action( | ||||||
parent, text, icon, package, module, args=None | ||||||
): | ||||||
"""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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
It seems missing. |
||||||
if is_text_string(icon): | ||||||
icon = ima.get_icon(icon) | ||||||
if programs.python_script_exists(package, module): | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
For clarity. |
||||||||
# Actions | ||||||||
original_back_action = self.pageAction(QWebEnginePage.WebAction.Back) | ||||||||
back_action = self.create_action( | ||||||||
|
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.
Our custom is not add code before calling
super
unless it's really necessary.