Skip to content

Commit 6b3b7dd

Browse files
mishagaShagov
andauthored
fix: IsUrl for 2nd version of pydantic (#74)
Closes issue #72 Co-authored-by: Shagov <shagov@tochka.com>
1 parent ff11d24 commit 6b3b7dd

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

‎dirty_equals/_other.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def __init__(
216216
RedisDsn,
217217
ValidationError,
218218
parse_obj_as,
219+
version,
219220
)
220221

221222
self.AmqpDsn = AmqpDsn
@@ -227,6 +228,7 @@ def __init__(
227228
self.RedisDsn = RedisDsn
228229
self.parse_obj_as = parse_obj_as
229230
self.ValidationError = ValidationError
231+
self.pydantic_version = version.VERSION
230232
except ImportError as e:
231233
raise ImportError('pydantic is not installed, run `pip install dirty-equals[pydantic]`') from e
232234
url_type_mappings = {
@@ -260,13 +262,15 @@ def equals(self, other: Any) -> bool:
260262
parsed = self.parse_obj_as(self.url_type, other)
261263
except self.ValidationError:
262264
raise ValueError('Invalid URL')
265+
266+
equal = parsed == other if self.pydantic_version < '2' else parsed.unicode_string() == other
263267
if not self.attribute_checks:
264-
return parsed == other
268+
return equal
265269

266270
for attribute, expected in self.attribute_checks.items():
267271
if getattr(parsed, attribute) != expected:
268272
return False
269-
return parsed == other
273+
return equal
270274

271275

272276
HashTypes = Literal['md5', 'sha-1', 'sha-256']

‎docs/usage.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ assert repr(IsInt()) == 'IsInt()'
5757
assert repr(IsApprox(42)) == 'IsApprox(approx=42)'
5858
```
5959

60-
However the repr method of types changes when an equals (`==`) operation on them returns a `True`, in this case
60+
However, the repr method of types changes when an equals (`==`) operation on them returns a `True`, in this case
6161
the `__repr__` method will return `repr(other)`.
6262

6363
```py title="repr() after comparison"

0 commit comments

Comments
 (0)