title: Generic[T] base class - how to get type of T from within instance?
body: <p>Assume you have a Python class that inherits from Generic[T]. Is there any way to get a hold of the actual type passed in from within the class/instance?</p>
  
  <p>For example,</p>
  
  <pre><code>from typing import TypeVar, Type
  T = TypeVar('T')
  
  class Test(Generic[T]):
      def hello(self):
        my_type = T  # this is wrong!
        print( "I am {0}".format(my_type) )
  
  Test[int]().hello() # should print "I am int"
  </code></pre>
  
  <p>On <a href="https://stackoverflow.com/questions/48572831/how-to-access-the-type-arguments-of-typing-generic">here</a>, it is suggested the type arg would be present in in the args field of the type. And indeed,</p>
  
  <pre><code>print( str( Test[int].__args__ ) )
  </code></pre>
  
  <p>would print (&lt;class 'int'&gt;,). However, I can't seem to access this from within the instance directly, e.g. substituting</p>
  
  <pre><code>      my_type = self.__class__.__args__ # this is also wrong (None)
  </code></pre>
  
  <p>doesn't seem to to the trick.</p>
  
  <p>Thanks</p>