0

I need to do some introspection on dataclasses. currently, the project is running on python 3.8, but soon, it will be upgraded. However, right now, I would like to know how I can check if a type is a GenericAlias, and get its t_orig, and t_args. How can I do is so that :

  • On python 3.8 :

    • It works with typing.List[int]
  • On python 3.9+ :

    • It works with typing.List[int]
    • It works with list[int]
  • The same code works all 3.8+ versions

2
  • 2
    Does get_args/get_origin not work for you? What exactly do you want to check? Just if something is list[int]/List[int] or something more general about generic alias types? Jun 6 at 10:56
  • Yup, that's the solution I've found after I asked the question, and it's all I needed !
    – hl037_
    Jun 6 at 13:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.