diff --git a/mode/python/python.js b/mode/python/python.js
index 3a86c278a1151f203a6f765bcc8e445e82552843..45dd63ba48a365fc3776467fc674b97135de75e1 100644
--- a/mode/python/python.js
+++ b/mode/python/python.js
@@ -320,8 +320,10 @@
         var closing = textAfter && textAfter.charAt(0) == scope.type;
         if (scope.align != null)
           return scope.align - (closing ? 1 : 0);
+        else if (closing && state.scopes.length > 1)
+          return state.scopes[state.scopes.length - 2].offset;
         else
-          return scope.offset - (closing ? conf.indentUnit : 0);
+          return scope.offset;
       },
 
       lineComment: "#",