99import logging
1010import types
1111import datetime
12+ import uuid
1213from enum import Enum
1314from copy import deepcopy
1415from math import isclose as is_close
@@ -108,6 +109,7 @@ def _report_progress(_stats, progress_logger, duration):
108109 'number_format_notation' ,
109110 'ignore_string_type_changes' ,
110111 'ignore_numeric_type_changes' ,
112+ 'ignore_uuid_types' ,
111113 'use_enum_value' ,
112114 'ignore_type_in_groups' ,
113115 'ignore_type_subclasses' ,
@@ -168,6 +170,7 @@ def __init__(self,
168170 ignore_string_type_changes : bool = False ,
169171 ignore_type_in_groups : Optional [List [Tuple ]]= None ,
170172 ignore_type_subclasses : bool = False ,
173+ ignore_uuid_types : bool = False ,
171174 include_obj_callback : Optional [Callable ]= None ,
172175 include_obj_callback_strict : Optional [Callable ]= None ,
173176 include_paths : Union [str , List [str ], None ]= None ,
@@ -199,7 +202,7 @@ def __init__(self,
199202 "The following parameter(s) are not valid: %s\n "
200203 "The valid parameters are ignore_order, report_repetition, significant_digits, "
201204 "number_format_notation, exclude_paths, include_paths, exclude_types, exclude_regex_paths, ignore_type_in_groups, "
202- "ignore_string_type_changes, ignore_numeric_type_changes, ignore_type_subclasses, truncate_datetime, "
205+ "ignore_string_type_changes, ignore_numeric_type_changes, ignore_type_subclasses, ignore_uuid_types, truncate_datetime, "
203206 "ignore_private_variables, ignore_nan_inequality, number_to_string_func, verbose_level, "
204207 "view, hasher, hashes, max_passes, max_diffs, zip_ordered_iterables, "
205208 "cutoff_distance_for_pairs, cutoff_intersection_for_pairs, log_frequency_in_sec, cache_size, "
@@ -222,6 +225,11 @@ def __init__(self,
222225 self .ignore_numeric_type_changes = ignore_numeric_type_changes
223226 if strings == ignore_type_in_groups or strings in ignore_type_in_groups :
224227 ignore_string_type_changes = True
228+ # Handle ignore_uuid_types - check if uuid+str group is already in ignore_type_in_groups
229+ uuid_str_group = (uuids [0 ], str )
230+ if uuid_str_group == ignore_type_in_groups or uuid_str_group in ignore_type_in_groups :
231+ ignore_uuid_types = True
232+ self .ignore_uuid_types = ignore_uuid_types
225233 self .use_enum_value = use_enum_value
226234 self .log_scale_similarity_threshold = log_scale_similarity_threshold
227235 self .use_log_scale = use_log_scale
@@ -233,7 +241,8 @@ def __init__(self,
233241 ignore_type_in_groups = ignore_type_in_groups ,
234242 ignore_string_type_changes = ignore_string_type_changes ,
235243 ignore_numeric_type_changes = ignore_numeric_type_changes ,
236- ignore_type_subclasses = ignore_type_subclasses )
244+ ignore_type_subclasses = ignore_type_subclasses ,
245+ ignore_uuid_types = ignore_uuid_types )
237246 self .report_repetition = report_repetition
238247 self .exclude_paths = add_root_to_paths (convert_item_or_items_into_set_else_none (exclude_paths ))
239248 self .include_paths = add_root_to_paths (convert_item_or_items_into_set_else_none (include_paths ))
@@ -1710,7 +1719,18 @@ def _diff(self, level, parents_ids=frozenset(), _original_type=None, local_tree=
17101719 self ._diff_booleans (level , local_tree = local_tree )
17111720
17121721 elif isinstance (level .t1 , strings ):
1713- self ._diff_str (level , local_tree = local_tree )
1722+ # Special handling when comparing string with UUID and ignore_uuid_types is True
1723+ if self .ignore_uuid_types and isinstance (level .t2 , uuids ):
1724+ try :
1725+ # Convert string to UUID for comparison
1726+ t1_uuid = uuid .UUID (level .t1 )
1727+ if t1_uuid .int != level .t2 .int :
1728+ self ._report_result ('values_changed' , level , local_tree = local_tree )
1729+ except (ValueError , AttributeError ):
1730+ # If string is not a valid UUID, report as changed
1731+ self ._report_result ('values_changed' , level , local_tree = local_tree )
1732+ else :
1733+ self ._diff_str (level , local_tree = local_tree )
17141734
17151735 elif isinstance (level .t1 , datetime .datetime ):
17161736 self ._diff_datetime (level , local_tree = local_tree )
@@ -1722,7 +1742,18 @@ def _diff(self, level, parents_ids=frozenset(), _original_type=None, local_tree=
17221742 self ._diff_time (level , local_tree = local_tree )
17231743
17241744 elif isinstance (level .t1 , uuids ):
1725- self ._diff_uuids (level , local_tree = local_tree )
1745+ # Special handling when comparing UUID with string and ignore_uuid_types is True
1746+ if self .ignore_uuid_types and isinstance (level .t2 , str ):
1747+ try :
1748+ # Convert string to UUID for comparison
1749+ t2_uuid = uuid .UUID (level .t2 )
1750+ if level .t1 .int != t2_uuid .int :
1751+ self ._report_result ('values_changed' , level , local_tree = local_tree )
1752+ except (ValueError , AttributeError ):
1753+ # If string is not a valid UUID, report as changed
1754+ self ._report_result ('values_changed' , level , local_tree = local_tree )
1755+ else :
1756+ self ._diff_uuids (level , local_tree = local_tree )
17261757
17271758 elif isinstance (level .t1 , numbers ):
17281759 self ._diff_numbers (level , local_tree = local_tree , report_type_change = report_type_change )
0 commit comments