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

Change field encode_name inspection #39

Open
Olegt0rr opened this issue Apr 23, 2024 · 0 comments
Open

Change field encode_name inspection #39

Olegt0rr opened this issue Apr 23, 2024 · 0 comments

Comments

@Olegt0rr
Copy link
Owner

          `msgspec.inspect.type_info` is one way, but it's a bit overkill for this use case. And `__struct_encode_fields__` is technically non-public (and may be removed in the future). The best way to get this information is to use `msgspec.struct.fields` ([docs](https://jcristharif.com/msgspec/api.html#msgspec.structs.fields)). You're looking for the `encode_name` attribute on `FieldInfo` in the result:
In [3]: class Example(msgspec.Struct):
   ...:     user_id: int = msgspec.field(name="userId")
   ...: 

In [4]: msgspec.structs.fields(Example)
Out[4]: (FieldInfo(name='user_id', encode_name='userId', type=<class 'int'>, default=NODEFAULT, default_factory=NODEFAULT),)

Originally posted by @jcrist in jcrist/msgspec#672 (comment)

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

No branches or pull requests

1 participant