Skip to content

Commit

Permalink
fix pydantic version checking (#80)
Browse files Browse the repository at this point in the history
Co-authored-by: Shagov <shagov@tochka.com>
  • Loading branch information
mishaga and Shagov authored Sep 15, 2023
1 parent 9a93a17 commit 9ea7e27
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions dirty_equals/_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ def __init__(
self.RedisDsn = RedisDsn
self.parse_obj_as = parse_obj_as
self.ValidationError = ValidationError
self.pydantic_version = version.VERSION
self.pydantic_version = tuple(map(int, version.VERSION.split('.')))

except ImportError as e:
raise ImportError('pydantic is not installed, run `pip install dirty-equals[pydantic]`') from e
url_type_mappings = {
Expand Down Expand Up @@ -264,7 +265,11 @@ def equals(self, other: Any) -> bool:
except self.ValidationError:
raise ValueError('Invalid URL')

equal = parsed == other if self.pydantic_version < '2' else parsed.unicode_string() == other
if self.pydantic_version[0] == 1: # checking major version
equal = parsed == other
else:
equal = parsed.unicode_string() == other

if not self.attribute_checks:
return equal

Expand Down

0 comments on commit 9ea7e27

Please sign in to comment.