Skip to content

Commit

Permalink
Remopve mutable defaults for keyword arguments. Partially addresses s…
Browse files Browse the repository at this point in the history
  • Loading branch information
gb119 committed Dec 15, 2024
1 parent 49e81ef commit 5b48c3a
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 20 deletions.
5 changes: 3 additions & 2 deletions external-deps/qtconsole/qtconsole/ansi_code_processor.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion installers-conda/build_conda_pkgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class BuildCondaPkg:
feedstock_branch = None
shallow_ver = None

def __init__(self, data={}, debug=False, shallow=False):
def __init__(self, data=None, debug=False, shallow=False):
data = {} if data is None else data
self.logger = getLogger(self.__class__.__name__)
if not self.logger.handlers:
self.logger.addHandler(h)
Expand Down
3 changes: 2 additions & 1 deletion spyder/plugins/completion/confpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@


class CompletionConfigPage(PluginConfigPage):
def __init__(self, plugin, parent, providers=[]):
def __init__(self, plugin, parent, providers=None):
providers = [] if providers is None else providers
super().__init__(plugin, parent)
self.providers = providers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,8 @@ def reload_model(self, language, defaults):
model.delete_queue = list(model.snippets)
self.load_snippets(language, model, defaults)

def load_snippets(self, language, model, snippets=None, to_add=[]):
def load_snippets(self, language, model, snippets=None, to_add=None):
to_add = [] if to_add is None else to_add
snippets = iter_snippets(language, self.parent.get_option,
self.parent.set_option,
snippets=snippets)
Expand Down
3 changes: 2 additions & 1 deletion spyder/plugins/console/widgets/internalshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
super().__init__(parent, get_conf_path('history_internal.py'),
profile=profile)

Expand Down
3 changes: 2 additions & 1 deletion spyder/plugins/editor/widgets/codeeditor/codeeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2476,7 +2476,7 @@ def __number_of_spaces(self, line_text, group=0):
if len(spaces) - 1 >= group:
return len(spaces[group])

def __get_brackets(self, line_text, closing_brackets=[]):
def __get_brackets(self, line_text, closing_brackets=None):
"""
Return unmatched opening brackets and left-over closing brackets.
Expand All @@ -2493,6 +2493,7 @@ def __get_brackets(self, line_text, closing_brackets=[]):
be matched with previously unmatched opening brackets in this line.
3) Pos at which a # comment begins. -1 if it doesn't.'
"""
closing_brackets = [] if closing_brackets is None else closing_brackets
# Remove inline comment and check brackets
bracket_stack = [] # list containing this lines unmatched opening
# same deal, for closing though. Ignore if bracket stack not empty,
Expand Down
5 changes: 4 additions & 1 deletion spyder/plugins/explorer/widgets/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
self.CONF_SECTION = 'explorer'
super().__init__()

Expand Down
5 changes: 4 additions & 1 deletion spyder/plugins/findinfiles/widgets/combobox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
super().__init__(parent)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.setEditable(False)
Expand Down
9 changes: 7 additions & 2 deletions spyder/plugins/onlinehelp/pydoc_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,15 @@ def filelink(self, url, path):
"""Make a link to source file."""
return '<a href="file:%s">%s</a>' % (url, path)

def markup(self, text, escape=None, funcs={}, classes={}, methods={}):
def markup(self, text, escape=None, funcs=None, classes=None, methods=None):
"""
Mark up some plain text, given a context of symbols to look for.
Each context dictionary maps object names to anchor names.
"""
funcs = {} if funcs is None else funcs
classes = {} if classes is None else classes
methods = {} if methods is None else methods
escape = escape or self.escape
results = []
here = 0
Expand Down Expand Up @@ -370,9 +373,11 @@ def docmodule(self, object, name=None, mod=None, *ignored):

return result

def docclass(self, object, name=None, mod=None, funcs={}, classes={},
def docclass(self, object, name=None, mod=None, funcs=None, classes=None,
*ignored):
"""Produce HTML documentation for a class object."""
funcs = {} if funcs is None else funcs
classes = {} if classes is None else classes
realname = object.__name__
name = name or realname
bases = object.__bases__
Expand Down
3 changes: 2 additions & 1 deletion spyder/plugins/onlinehelp/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class PydocBrowserToolbarItems:
try:
from pydoc import safeimport

def spyder_safeimport(path, forceload=0, cache={}):
def spyder_safeimport(path, forceload=0, cache=None):
cache = {} if cache is None else cache
if path in DIRECT_PYDOC_IMPORT_MODULES:
forceload = 0
return safeimport(path, forceload=forceload, cache=cache)
Expand Down
3 changes: 2 additions & 1 deletion spyder/plugins/variableexplorer/widgets/importwizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
self._data = data

Expand Down
3 changes: 2 additions & 1 deletion spyder/utils/bsdsocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ def read_packet(sock, timeout=None):

# * Old com implementation *
# See solution (1) in spyder-ide/spyder#434, comment 13:
def communicate(sock, command, settings=[]):
def communicate(sock, command, settings=None):
"""Communicate with monitor"""
settings = [] if settings is None else settings
try:
COMMUNICATE_LOCK.acquire()
write_packet(sock, command)
Expand Down
10 changes: 7 additions & 3 deletions spyder/utils/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
assert isinstance(args, (tuple, list)) and isinstance(p_args, (tuple, list))
path = python_script_exists(package, module)
Expand Down
3 changes: 2 additions & 1 deletion spyder/utils/qthelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,9 @@ 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
if is_text_string(icon):
icon = ima.get_icon(icon)
if programs.python_script_exists(package, module):
Expand Down
8 changes: 7 additions & 1 deletion spyder/utils/syntaxhighlighters.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,14 @@ def highlight_block(self, text):
#==============================================================================
# Python syntax highlighter
#==============================================================================
def make_python_patterns(additional_keywords=[], additional_builtins=[]):
def make_python_patterns(additional_keywords=None, additional_builtins=None):
"Strongly inspired from idlelib.ColorDelegator.make_pat"
additional_keywords = (
[] if additional_keywords is None else additional_keywords
)
additional_builtins = (
[] if additional_builtins is None else additional_builtins
)
kwlist = keyword.kwlist + additional_keywords
builtinlist = [str(name) for name in dir(builtins)
if not name.startswith('_')] + additional_builtins
Expand Down
3 changes: 2 additions & 1 deletion spyder/widgets/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# Actions
original_back_action = self.pageAction(QWebEnginePage.WebAction.Back)
back_action = self.create_action(
Expand Down

0 comments on commit 5b48c3a

Please sign in to comment.