Skip to content

Commit

Permalink
Avoid mutable types as default args.
Browse files Browse the repository at this point in the history
This change removes two places where we use a set as a default value.
Mutable containers should not be used as default arguments as they are
created when the function is defined (basically, the first time the
module is imported) and then that one instance is used anytime the
method is invoked without that argument specified.  This means that
changes to the container will persist to the next time the function is
invoked which could lead to bugs down the road.

I do not believe we're currently experiencing any bugs due to this as we
never seem to mutate the containers.  Instead, we use the data to make
new sets inside of the functions.
  • Loading branch information
abadger authored and bocekm committed Feb 22, 2022
1 parent 8b0881b commit 7464eb9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions convert2rhel/pkghandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def call_yum_cmd(
return stdout, returncode


def get_problematic_pkgs(output, excluded_pkgs=set()):
def get_problematic_pkgs(output, excluded_pkgs=frozenset()):
"""Parse the YUM/DNF output to find what packages are causing a transaction failure."""
loggerinst.info("Checking for problematic packages")
problematic_pkgs = {
Expand Down Expand Up @@ -201,7 +201,7 @@ def get_pkgs_to_distro_sync(problematic_pkgs):
)


def resolve_dep_errors(output, pkgs=set()):
def resolve_dep_errors(output, pkgs=frozenset()):
"""Recursive function. If there are dependency errors in the yum output,
try to resolve them by yum downgrades.
"""
Expand Down

0 comments on commit 7464eb9

Please sign in to comment.