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

Support Extending TypeSystems #243

Closed
JacobHayes opened this issue Jul 10, 2022 · 0 comments · Fixed by #250
Closed

Support Extending TypeSystems #243

JacobHayes opened this issue Jul 10, 2022 · 0 comments · Fixed by #250
Labels
enhancement New feature or request

Comments

@JacobHayes
Copy link
Member

JacobHayes commented Jul 10, 2022

Is your feature request related to a problem? Please describe.

Some TypeSystems will overlap (eg: pydantic is an extension of python; pandas types are an extension of numpy ones). When these overlap, we often just hard code references to the other TypeSystem instance in the TypeAdapter code. This is a bit "brittle" because sometimes we want to convert both the base types + extended types.

Describe the solution you'd like

Add a TypeSystem "extends" (or similarly named) field that points to other TypeSystem to inherit from. For example, pydantic_type_system = TypeSystem(key="pydantic", extends=[python_type_system]). Then, to_{artigraph,system} would first check its own TypeAdapters before falling back to the extended systems' adapters.

Then, we'll need to pass the "root" TypeSystem around into the TypeAdapters and use that instead of any hard coded references to TypeSystems; replacing those hard coded references with extends in their TypeSystem.

Describe alternatives you've considered

The pydantic_type_system works around this / a similar issue when converting nested models by registering a _PythonBaseModelAdapter on the python_type_system - this allows us to just call python_type_system when converting from the pydantic BaseModelAdapter to handle both python natives + sub-models. Instead, we could have the pydantic_type_system extend python natively and then letself.type_system in the Pydantic TypeAdapters handle the extension.

@JacobHayes JacobHayes added the enhancement New feature or request label Jul 10, 2022
@JacobHayes JacobHayes changed the title Support reusing a TypeAdapter with multiple TypeSystems Support Extending TypeSystems Jul 10, 2022
@JamesOswald JamesOswald mentioned this issue Jul 19, 2022
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant