@@ -38,8 +38,17 @@ def compare_config(
3838 :return: a ConfigChange objects.
3939 """
4040 diff = defaultdict (list [LibraryChange ])
41- baseline_params = __convert_params_to_sorted_list (baseline_config )
42- current_params = __convert_params_to_sorted_list (current_config )
41+ # Exclude `libraries` because an empty library list (e.g., by library
42+ # removal) will cause this parameter appears in the sorted param list,
43+ # which leads to unequal list of parameters.
44+ excluded_params = {"libraries" }
45+ baseline_params = __convert_params_to_sorted_list (
46+ obj = baseline_config , excluded_params = excluded_params
47+ )
48+ current_params = __convert_params_to_sorted_list (
49+ obj = current_config , excluded_params = excluded_params
50+ )
51+
4352 for baseline_param , current_param in zip (baseline_params , current_params ):
4453 if baseline_param == current_param :
4554 continue
@@ -216,7 +225,7 @@ def __compare_gapic_configs(
216225 diff [ChangeType .GAPIC_ADDITION ].append (config_change )
217226
218227
219- def __convert_params_to_sorted_list (obj : Any ) -> List [tuple ]:
228+ def __convert_params_to_sorted_list (obj : Any , excluded_params = None ) -> List [tuple ]:
220229 """
221230 Convert the parameter and its value of a given object to a sorted list of
222231 tuples.
@@ -230,13 +239,17 @@ def __convert_params_to_sorted_list(obj: Any) -> List[tuple]:
230239
231240 Note that built-in params, e.g., __str__, and methods will be skipped.
232241
233- :param obj: an object
242+ :param obj: an object.
243+ :param excluded_params: excluded params.
234244 :return: a sorted list of tuples.
235245 """
246+ if excluded_params is None :
247+ excluded_params = set ()
236248 param_and_values = []
237249 for param , value in vars (obj ).items ():
238250 if (
239- param .startswith ("__" ) # skip built-in params
251+ param in excluded_params
252+ or param .startswith ("__" ) # skip built-in params
240253 or callable (getattr (obj , param )) # skip methods
241254 # skip if the type of param is not one of the following types
242255 # 1. str
0 commit comments