title: can this variable really be "referenced before assignment"
body: <p>I have a piece of code below (belongs to a Django admin view, slightly modified). My IDE (PyCharm) warns me at the last line that <code>Local variable 'ModelForm' might be referenced before assignment</code>.</p>
  
  <p>I don't see how that can ever happen, but when I comment out line 6:</p>
  
  <pre><code>with transaction.commit_manually():
  </code></pre>
  
  <p>then the warning disappears.</p>
  
  <p>Am I missing something, or is PyCharm missing something?</p>
  
  <p>Here is the chunk of code. I striped it down to just a few lines and it still gives the warning. The original chunk of code is here (70 lines): <a href="http://pastebin.com/4UT9hRPb" rel="nofollow">http://pastebin.com/4UT9hRPb</a></p>
  
  <pre><code>    ModelForm = self.get_form(request, obj, form=form)
  
      formsets = []
      if request.method == 'POST':
          # commit only when all forms are valid
          with transaction.commit_manually():
              try:
                  objects = queryset.all()
                  transaction.commit()
                  return self.response_change(request, new_object)
  
              finally:
                  general_error = unicode(sys.exc_info()[1])
                  transaction.rollback()
  
      form = ModelForm()
  </code></pre>