Warn if a class inherits from Generic before BaseModel#7891
Merged
sydney-runkle merged 2 commits intopydantic:mainfrom Oct 29, 2023
Merged
Warn if a class inherits from Generic before BaseModel#7891sydney-runkle merged 2 commits intopydantic:mainfrom
sydney-runkle merged 2 commits intopydantic:mainfrom
Conversation
Contributor
|
Thanks for the contribution. I'll discuss this issue with the team tomorrow morning + follow up with you afterwards 😄. |
Contributor
|
Feel free to move ahead with this. We would like to warn if a class inherits from |
Contributor
Author
|
please review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change Summary
Emit a warning when writing:
instead of:
More generally,
BaseModelmust appear in the__mro__beforeGeneric, so indirect subclasses are also checked. This means that__class_getitem__will useBaseModelinstead ofGenericandModel[T]will return a model class rather than a_GenericAlias.Related issue number
Closes #7845
Waiting for a reply to #6994 (comment) before continuing here, but thought I should push what I have so far. The failing tests might be of interest.
Checklist
Selected Reviewer: @dmontagu