title: mypy type checking shows error when a variable gets dynamically allocated
body: <p>I have a class that takes a <code>Spark DataFrame</code> and does some processing to it. Here is the code:</p>
  
  <pre><code>    for column in self.sdf.columns:
          if column not in self.__columns:
              row = [column]
              row += '--' * 9
              column_table.append(row)
  </code></pre>
  
  <p>I have this code inside constructor of my class:</p>
  
  <pre><code>self.sdf: Optional[SparkDataFrame] = None
  </code></pre>
  
  <p>Here <code>sdf</code> is set dynamically during execution of my class and then the for loop mentioned above will run. <code>__columns</code> is a dictionary which is supposed to have all the columns of sdf. I found no errors in the code when it ran. But when I type checked my code with <code>mypy</code>, it showed an error on the first line of for loop: </p>
  
  <p><code>error: Item "None" of "Optional[Any]" has no attribute "columns"</code></p>
  
  <p>I understand that initially sdf will be <code>None</code>. But should I consider this a serious error? Is there are any workarounds for this?</p>