Initial Checks
Description
I'd like to see instances of the pydantic class SecretStr to be hashable like instances of the str class are hashable.
I use it mainly in instances of BaseSettings and during startup of a server application, I add settings classes which I can successfully construct in a set. This gives me an indication of missing configuration values.
But models containing fields annotated with SecretStr currently cannot be added to a set as Python complains about the SecretStr type: TypeError: unhashable type: 'SecretStr'
Example snippet:
import pydantic
class M(pydantic.BaseModel):
s: pydantic.SecretStr = pydantic.SecretStr("secret")
def __hash__(self):
return hash((type(self),) + tuple(self.__dict__.values()))
def test_can_hash():
assert hash(M())
Affected Components
Initial Checks
Description
I'd like to see instances of the pydantic class
SecretStrto be hashable like instances of thestrclass are hashable.I use it mainly in instances of
BaseSettingsand during startup of a server application, I add settings classes which I can successfully construct in a set. This gives me an indication of missing configuration values.But models containing fields annotated with
SecretStrcurrently cannot be added to a set as Python complains about theSecretStrtype:TypeError: unhashable type: 'SecretStr'Example snippet:
Affected Components
.dict()and.json()construct(), pickling, private attributes, ORM mode