-
Notifications
You must be signed in to change notification settings - Fork 90
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
Add new inspect
submodule
#253
Conversation
@Goldziher can you take a look through the types in |
98c5218
to
6bd7b1c
Compare
Ok, the code here is now mostly done (caveat - still needs tests). I've ported our builtin json-schema generation code over to consume the output of Remaining todos:
|
This adds a new `inspect` submodule. The main entrypoint in this submodule is `msgspec.inspect.type_info` which converts a python type annotation into a `msgspec.inspect.Type` tree. This can be useful for tools that want to programmatically work with msgspec type annotations. A few possible use cases: - Generating `openapi` documentation - Generating fake data from type annotations
Also moves all json-schema handling over to consume the output of `msgspec.inspect.multi_type_info`. Still needs tests and docs.
Ok, I believe this to be done. I'm pretty happy with the code quality, and think this provides a nice enough interface to build further tooling off of. I've marked this as "experimental" in the docs for now. Here this just means that I don't feel bad about making breaking changes to it between versions if issues turn up during use. I plan to merge this tomorrow evening if no comment. I would love for some feedback here from @Goldziher or @provinzkraut if y'all have time, but no pressure. |
Hi, sure - I'm flying today, so i might need a couple of days to go through this properly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Left some questions. I didn't see handling of TypedDict
. Also, hoe can I access the raw typing?
names.append(field.encode_name) | ||
fields.append(field_schema) | ||
if isinstance(t, mi.NamedTupleType): | ||
schema["type"] = "array" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of repetition. I'd consider using enums or constants
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expand on what you mean by that? How would enums or constants make this code more maintainable?
Handling of
You mean the original python type annotations? Those aren't exposed. Based on this comment:
it sounded like you didn't want access to the raw python type annotations, but instead wanted "a sort of syntax tree for typing information", which is what the functions and types in |
Merging this for now. Any additional information needed can be exposed in follow-up PRs. |
This adds a new
inspect
submodule. The main entrypoint in this submodule ismsgspec.inspect.type_info
which converts a python type annotation into amsgspec.inspect.Type
tree. This can be useful for tools that want to programmatically work with msgspec type annotations. A few possible use cases:openapi
documentationFixes #227.