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

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

Open
apirogov opened this issue Sep 1, 2022 · 1 comment
Open

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

apirogov opened this issue Sep 1, 2022 · 1 comment
Labels
enhancement New feature or request internals Technical and subtle issues users are (usually) not aware of prio:B UX Features and tools improving overall experience and practicality of Metador framework

Comments

@apirogov
Copy link
Collaborator

apirogov commented Sep 1, 2022

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

  • raise an exception if new type is not a subclass
  • otherwise substitute this schema in all (including inherited) type hints

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 apirogov added enhancement New feature or request prio:A prio:B and removed prio:A labels Sep 1, 2022
@apirogov apirogov changed the title Try to add way to override a type within a model for all fields Add a way to override a type within a model for all fields Sep 5, 2022
@apirogov
Copy link
Collaborator Author

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.

@apirogov apirogov added UX Features and tools improving overall experience and practicality of Metador framework internals Technical and subtle issues users are (usually) not aware of labels Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request internals Technical and subtle issues users are (usually) not aware of prio:B UX Features and tools improving overall experience and practicality of Metador framework
Projects
None yet
Development

No branches or pull requests

1 participant