File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
272276HashTypes = Literal ['md5' , 'sha-1' , 'sha-256' ]
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ assert repr(IsInt()) == 'IsInt()'
5757assert 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
6161the ` __repr__ ` method will return ` repr(other) ` .
6262
6363``` py title="repr() after comparison"
You can’t perform that action at this time.
0 commit comments