-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Raise a better error when a generic alias is used inside type[]
#11088
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
Conversation
if _typing_extra.is_generic_alias(type_param): | ||
raise PydanticUserError( | ||
'Subscripting `type[]` with an already parametrized type is not supported. ' | ||
f'Instead of using type[{type_param!r}], use type[{_repr.display_as_type(get_origin(type_param))}].', |
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.
Because type_param
is a generic alias, we can rely on its __repr__
implementation, which uses typing._type_repr
to do a pretty representation already.
However, we still use our _repr.display_as_type
(inspired by typing._type_repr
) for the origin, which is not a generic alias anymore but a proper class.
This should cover most use cases.
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.
This looks good. @dmontagu mentioned that we might want to support this eventually, so can we say "not yet supported", and link to the issue?
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.
Imo trying to support this is going to introduce lots of maintenance burden for the reason I mentioned in #11000 (comment), and maybe not possible at all as mentioned in #10462 (comment).
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.
Fair enough, should we close #11000 then?
CodSpeed Performance ReportMerging #11088 will not alter performanceComparing Summary
|
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
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.
Thanks!
As per #11000 (comment).
Change Summary
Related issue number
Checklist