title: Type Hints Convention for Instance Variables Python
body: <p>I'm unsure of the Python convention for type hinting instance variables - I've been doing them within the <code>__init__</code> constructor arguments <a href="https://docs.python.org/3/library/typing.html#user-defined-generic-types" rel="noreferrer">like seen here</a>:</p>
  <pre><code>class LoggedVar(Generic[T]):
      def __init__(self, value: T, name: str, logger: Logger) -&gt; None:
          self.name = name
          self.logger = logger
          self.value = value`
  </code></pre>
  <p>But I also see the PEP conventions of annotating instance variables as such (snippet below) and then also doing type hinting within the <code>__init__</code> arguments:</p>
  <pre><code>class BasicStarship:
      captain: str = 'Picard'               # instance variable with default
      damage: int                           # instance variable without default
      stats: ClassVar[Dict[str, int]] = {}  # class variable`
  
      def __init__(self, damage: int, captain: str = None):
          self.damage = damage
          if captain:
              self.captain = captain  # Else keep the default
  </code></pre>
  <p>Lastly, later on in the PEP 526 article they say one can do the following for convenience and convention:</p>
  <pre><code>class Box(Generic[T]):
      def __init__(self, content):
          self.content: T = content
  </code></pre>
  <p>(Both of the above code snippets are from <a href="https://www.python.org/dev/peps/pep-0526/#class-and-instance-variable-annotations" rel="noreferrer">here</a>.)</p>
  <p>So — is one of these conventions better/more widely accepted than the others that I should try to stick to (better readability etc..)?</p>