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

feat: add repr kwarg to field function and Field C struct #543

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
## PyCharm/IntelliJ-generated files
*.iml
.idea/
## Vim-generated files
*.sw[op]

# Python cached sources
__pycache__/
Expand Down
6 changes: 4 additions & 2 deletions msgspec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
)


def field(*, default=NODEFAULT, default_factory=NODEFAULT, name=None):
return _Field(default=default, default_factory=default_factory, name=name)
def field(*, default=NODEFAULT, default_factory=NODEFAULT, name=None, repr=True):
return _Field(
default=default, default_factory=default_factory, name=name, repr=repr
)


def from_builtins(
Expand Down
8 changes: 5 additions & 3 deletions msgspec/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ class _NoDefault(enum.Enum):
NODEFAULT = _NoDefault.NODEFAULT

@overload
def field(*, default: T, name: Optional[str] = None) -> T: ...
def field(*, default: T, name: Optional[str] = None, repr: bool = True) -> T: ...
@overload
def field(*, default_factory: Callable[[], T], name: Optional[str] = None) -> T: ...
def field(
*, default_factory: Callable[[], T], name: Optional[str] = None, repr: bool = True
) -> T: ...
@overload
def field(*, name: Optional[str] = None) -> Any: ...
def field(*, name: Optional[str] = None, repr: bool = True) -> Any: ...
@dataclass_transform(field_specifiers=(field,))
class Struct:
__struct_fields__: ClassVar[Tuple[str, ...]]
Expand Down
Loading