You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@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 commentedon 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 commentedon Apr 26, 2020
New changeset 68b352a by Serhiy Storchaka in branch 'master':
bpo-40396: Support GenericAlias in the typing functions. (GH-19718)
68b352a
danielkatzan commentedon Aug 1, 2022
@serhiy-storchaka
why does
get_origin(list)returnsNonewhileget_origin(List)returns<class 'list'>shouldn't list behaves exactly the same as List? (the same question applies to all generics)
gvanrossum commentedon 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 commentedon 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__attributeI 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 commentedon Aug 1, 2022
This issue was closed 2 years ago, please open a new issue.
The fact that
get_origin(List)returnslistis not documented. It looks to me like an implementation artifact.AlexWaygood commentedon 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 commentedon Aug 1, 2022
opened this #95539