From 7464eb9d8ea5ba89f4e8d4f28e66a08d44c3ff02 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 24 Nov 2021 14:15:05 -0800 Subject: [PATCH] Avoid mutable types as default args. 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. --- convert2rhel/pkghandler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/convert2rhel/pkghandler.py b/convert2rhel/pkghandler.py index 75f60ca1b3..248495a553 100644 --- a/convert2rhel/pkghandler.py +++ b/convert2rhel/pkghandler.py @@ -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 = { @@ -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. """