-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
typing.get_origin behaves differently between standard collections and typing collections #95539
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
Comments
The fact that Many things in the What is the use case for |
This had a side effect on the behavior of the pydantic package, which has some logic to determine the An example was documented here |
Does this code work as intended? I see few suspicious things:
|
the code actually works
but now that you point it out, some adjustments will still need to be made to support Anyway, regardless to that package code\usage or assumptions, I was just thinking that since also fine to leave as if there is a disagreement here |
Makes sense to me. |
If you need to use a wrapper for If you make It is also not clear what change do you need. Should it only work with a limited set of builtin Python types and types defined in the stdlib? Should it work with arbitrary type? Or any type with |
Yep, can definitely do that, but I think the discussion here is regardless of the usage of the pydantic package I think it's a general discussion on what is the expected behaviour of I think the guideline should be to make standard collections behave as similar as possible to the typing collections in order to allow for easier transition between them (as I understand the collections from the typing module are expected to be deprecated in the future) so for context, I'm a user of the pydantic package, and just trying to make my first steps in open source contributing :), and came across that bug opened for pydantic, which led my to this issue. I'm not aware enough to all the implications or nuances such a change might impose |
Bug report
typing.get_origin behaves differently between standard collections, and typing collections
more specifically
get_origin(dict)
isNone
, whileget_origin(Dict)
is<class 'dict'>
the same holds for other collections as well
This is true from python3.9 where support for standard collections was added
to my understanding dict should be able to be a drop-in replacement for Dict, which is not true in case relying on get_origin
I suggest updating get_origin to return the relevant class for builtin collections as opposed to
None
which returns todaynote, this might mean a breaking change, as pointed out here, but id does make Dict and dict behave more similarly
The text was updated successfully, but these errors were encountered: