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鈥檒l 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 2 commits
Commits
File filter

Filter by extension

Filter by extension

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


@_dataclasses.dataclass()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we make it a slots dataclass like EncodeBytes?

Suggested change
@_dataclasses.dataclass()
@_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