Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Make EncodedStr a dataclass #7396

Merged
merged 5 commits into from
Sep 20, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pydantic/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,7 @@ def __hash__(self) -> int:
return hash(self.encoder)


@_dataclasses.dataclass(**_internal_dataclass.slots_true)
class EncodedStr(EncodedBytes):
"""A str type that is encoded and decoded using the specified encoder."""

Expand Down Expand Up @@ -1551,6 +1552,9 @@ def encode_str(self, value: str) -> str:
"""
return super().encode(value=value.encode()).decode()

def __hash__(self) -> int:
return hash(self.encoder)


Base64Bytes = Annotated[bytes, EncodedBytes(encoder=Base64Encoder)]
"""A bytes type that is encoded and decoded using the standard (non-URL-safe) base64 encoder."""
Expand Down
Loading