Created
April 19, 2022 00:40
-
-
Save malcolmgreaves/b774878a3f650626c4d54d2df5a38930 to your computer and use it in GitHub Desktop.
Allows one to obtain all concrete generic type arguments for any Python type.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List, Sequence, get_args | |
def get_args_all(t: type) -> List[type]: | |
all_args: List[type] = [] | |
all_args.extend(get_args(t)) | |
try: | |
orig_bases = t.__orig_bases__ | |
except AttributeError: | |
pass | |
else: | |
for x in orig_bases: | |
all_args.extend(get_args_all(x)) | |
return all_args |
Author
malcolmgreaves
commented
Apr 19, 2022
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment