@danielkatzan Looks like an omission in the code for get_origin(). Would you like to submit a PR to fix it? I can't promise that it will make it into 3.11 but it will be in 3.11.1.
@gvanrossum Sure, I would be happy to, but could use a little pointer here
Not sure how this can be accomplished
note while type(list[str]) is <class 'types.GenericAlias'> and has the __origin__ attribute, type(list) is actually <class 'type'> and doesn't have an __origin__ attribute
I can add an explicit if, checking if the tp is actually dict\list etc, and return that instead of None
will that be a valid approach? or just masking a deeper issue that might pop up later in a different location?
Activity
serhiy-storchaka commented on Apr 26, 2020
Currently typing functions get_origin(), get_args() and get_type_hints() do not support GenericAlias.
The proposed PR fixes this.
serhiy-storchaka commented on Apr 26, 2020
New changeset 68b352a by Serhiy Storchaka in branch 'master':
bpo-40396: Support GenericAlias in the typing functions. (GH-19718)
68b352a
danielkatzan commented on Aug 1, 2022
@serhiy-storchaka
why does get_origin(list) returns None while get_origin(List) returns <class 'list'>
shouldn't list behaves exactly the same as List? (the same question applies to all generics)
gvanrossum commented on Aug 1, 2022
@danielkatzan Looks like an omission in the code for get_origin(). Would you like to submit a PR to fix it? I can't promise that it will make it into 3.11 but it will be in 3.11.1.
danielkatzan commented on Aug 1, 2022
@gvanrossum Sure, I would be happy to, but could use a little pointer here
Not sure how this can be accomplished
note while type(list[str]) is <class 'types.GenericAlias'> and has the __origin__ attribute, type(list) is actually <class 'type'> and doesn't have an __origin__ attribute
I can add an explicit if, checking if the tp is actually dict\list etc, and return that instead of None
will that be a valid approach? or just masking a deeper issue that might pop up later in a different location?
serhiy-storchaka commented on Aug 1, 2022
This issue was closed 2 years ago, please open a new issue.
The fact that get_origin(List) returns list is not documented. It looks to me like an implementation artifact.
AlexWaygood commented on Aug 1, 2022
Changing that would be a breaking change at this point (at least... it would break code that I, personally, have written).
danielkatzan commented on Aug 1, 2022
opened this #95539