Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.2k
Raise a better error when a generic alias is used insidetype[]
#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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
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.
Becausetype_param
is a generic alias, we can rely on its__repr__
implementation, which usestyping._type_repr
to do a pretty representation already.
However, we still use our_repr.display_as_type
(inspired bytyping._type_repr
) for the origin, which isnot 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 willnot alter performanceComparing Summary
|
Coverage reportClick to see where and how coverage changed
This report was generated bypython-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!
c393317
intomainUh oh!
There was an error while loading.Please reload this page.
As per#11000 (comment).
Change Summary
Related issue number
Checklist