I would have thought that a1 == a2 here:
>>> import pydantic; print(pydantic.VERSION)
1.2
>>> from pydantic import BaseModel, SecretStr
>>> class A(BaseModel):
... a: SecretStr
...
>>> a1 = A(a='abcd')
>>> a2 = A(a='abcd')
>>> a1 == a2
False
Please complete:
import pydantic; print(pydantic.VERSION): 1.2Humm, good question. Also, what should happen if you compare SecretStr('xxx') == 'xxx'?
I think it should either work or raise an expressive exception. It should also be documented.
Feedback welcome.
In my use case i have a big structure where I relied on if new == old: return when one of the sub sub items introduced a secret string and then suddenly new was never equal to old anymore.
With a json_encoder for SecretStr (lambda x: x.get_secret_value()) I now tentatively rely on new.json() == old.json()
Okay, I'll accept a PR to fix SecretStr('xxx') == SecretStr('xxx'), let's leave the case of SecretStr('xxx') != 'xxx' for now.
PR welcome.
Most helpful comment
Okay, I'll accept a PR to fix
SecretStr('xxx') == SecretStr('xxx'), let's leave the case ofSecretStr('xxx') != 'xxx'for now.PR welcome.