Skip to content

Add Struct.__struct_config__ attribute - #328

Merged
jcrist merged 1 commit into
mainfrom
expose-struct-config-on-structs
Feb 19, 2023
Merged

Add Struct.__struct_config__ attribute#328
jcrist merged 1 commit into
mainfrom
expose-struct-config-on-structs

Conversation

@jcrist

@jcrist jcrist commented Feb 19, 2023

Copy link
Copy Markdown
Member

This adds a new __struct_config__ attribute to struct classes and instances. This attribute holds a (dynamically created) msgspec.structs.StructConfig instance describing the configuration settings for the respective struct type. Note that these settings are immutable; this object is only useful for type introspection, not for modifying settings of existing types.

Previously these settings were exposed through private (and undocumented) attributes. Those attributes have all been removed in favor of this new public interface.

class Point(msgspec.Struct, frozen=True):
    x: int
    y: int

assert Point.__struct_config__.frozen

Fixes #327.

This adds a new `__struct_config__` attribute to struct classes and
instances. This attribute holds a (dynamically created)
`msgspec.structs.StructConfig` instance describing the configuration
settings for the respective struct type. Note that these settings are
immutable; this object is only useful for type introspection, not for
modifying settings of existing types.

Previously these settings were exposed through private (and
undocumented) attributes. Those attributes have all been removed in
favor of this new public interface.

```python
class Point(msgspec.Struct, frozen=True):
    x: int
    y: int

assert Point.__struct_config__.frozen
```
@jcrist
jcrist merged commit 71cbfcd into main Feb 19, 2023
@jcrist
jcrist deleted the expose-struct-config-on-structs branch February 19, 2023 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

question: how to query options used to create Struct

1 participant