Repository: python/mypy

Issue:
stubgen misunderstands NO=FALSE=OFF=0
NO makes it to the generated stub file, but FALSE, OFF, and other variables defined on the same line do not.

Found while attempting to generate stubs for tkinter and running "stubgen tkinter.constants". The resulting file has "NO", but not "FALSE" or "OFF."

stubgen misunderstands NO=FALSE=OFF=0
NO makes it to the generated stub file, but FALSE, OFF, and other variables defined on the same line do not.

Found while attempting to generate stubs for tkinter and running "stubgen tkinter.constants". The resulting file has "NO", but not "FALSE" or "OFF."



Discussion:

Resolving patch:
diff --git a/mypy/stubgen.py b/mypy/stubgen.py
--- a/mypy/stubgen.py
+++ b/mypy/stubgen.py
@@ -330,29 +330,34 @@ def get_base_types(self, cdef: ClassDef) -> List[str]:
         return base_types
 
     def visit_assignment_stmt(self, o: AssignmentStmt) -> None:
-        lvalue = o.lvalues[0]
-        if isinstance(lvalue, NameExpr) and self.is_namedtuple(o.rvalue):
-            self.process_namedtuple(lvalue, o.rvalue)
-            return
-        if isinstance(lvalue, TupleExpr):
-            items = lvalue.items
-        elif isinstance(lvalue, ListExpr):
-            items = lvalue.items
-        else:
-            items = [lvalue]
-        sep = False
-        found = False
-        for item in items:
-            if isinstance(item, NameExpr):
-                init = self.get_init(item.name)
-                if init:
-                    found = True
-                    if not sep and not self._indent and self._state not in (EMPTY, VAR):
-                        init = '\n' + init
-                        sep = True
-                    self.add(init)
-                    self.record_name(item.name)
-        if found:
+        foundl = []
+
+        for lvalue in o.lvalues:
+            if isinstance(lvalue, NameExpr) and self.is_namedtuple(o.rvalue):
+                self.process_namedtuple(lvalue, o.rvalue)
+                continue
+            if isinstance(lvalue, TupleExpr):
+                items = lvalue.items
+            elif isinstance(lvalue, ListExpr):
+                items = lvalue.items
+            else:
+                items = [lvalue]
+            sep = False
+            found = False
+            for item in items:
+                if isinstance(item, NameExpr):
+                    init = self.get_init(item.name)
+                    if init:
+                        found = True
+                        if not sep and not self._indent and \
+                           self._state not in (EMPTY, VAR):
+                            init = '\n' + init
+                            sep = True
+                        self.add(init)
+                        self.record_name(item.name)
+            foundl.append(found)
+
+        if all(foundl):
             self._state = VAR
 
     def is_namedtuple(self, expr: Node) -> bool:


Test patch:
diff --git a/mypy/test/data/stubgen.test b/mypy/test/data/stubgen.test
--- a/mypy/test/data/stubgen.test
+++ b/mypy/test/data/stubgen.test
@@ -81,6 +81,14 @@ from typing import Any
 
 x = ...  # type: Any
 
+[case testMultipleVariable]
+x = y = 1
+[out]
+from typing import Any
+
+x = ...  # type: Any
+y = ...  # type: Any
+
 [case testClassVariable]
 class C:
     x = 1