Materials-Data-Science-and-Informatics / metador-core

Core of Metador, the FAIR metadata-first research data management framework.
MIT License
4 stars 0 forks source link

Add a way to override a type within a model for all fields #34

Open apirogov opened 2 years ago

apirogov commented 2 years ago

When subclassing a schema, e.g. to say "use MyPerson instead of Person in all fields"

Otherwise each field must be overridden explicitly, which is error prone or confusing.

Again the question arises: Decorator? Meta-class? this should not be too annoying to use.

Maybe the decorator should look like

@specialize_schema(schemaorg.Person, rocrate.Person, fields={"names", "where", "to", "substitute"})
class MyThing(schemaorgbasedThing):
 ...

and should

In all other cases (not specializing to a subtype) it should remain a manual type hint, otherwise it would be to easy to wreak havoc.

apirogov commented 2 years ago

Given the current state of things, it should be possible, using an approach similar to the make_mandatory decorator and combining it with a type hint traversal to substitute the type.

Main question is to make sure that this also works fine with Partial and Fields and the cached type hints.