2

Is there a way to get the value of an instantiated generic type at runtime? As in the following code:

T = TypeVar("T")
class Foo(Generic[T]):
    def __init__(self):
        print(f"instantiated type: {???}")  

o1 = Foo[int]() # this should print int
o2 = Foo[bool]() # this should print bool

What should I put in the ??? to print the appropriate values?

JRR
  • 6,014
  • 6
  • 39
  • 59
  • Does this answer your question? https://stackoverflow.com/questions/57706180/generict-base-class-how-to-get-type-of-t-from-within-instance – Anonymous12358 Jul 14 '22 at 13:06

0 Answers0