[case testEmptyFile]
[out]
MypyFile:1()

[case testGlobalVariable]
x = 1
x
[out]
MypyFile:1(
  AssignmentStmt:1(
    NameExpr(x* [__main__.x])
    IntExpr(1))
  ExpressionStmt:2(
    NameExpr(x [__main__.x])))

[case testMultipleGlobals]
x = y = 2
z = 3
(x, y, z)
[out]
MypyFile:1(
  AssignmentStmt:1(
    Lvalues(
      NameExpr(x* [__main__.x])
      NameExpr(y* [__main__.y]))
    IntExpr(2))
  AssignmentStmt:2(
    NameExpr(z* [__main__.z])
    IntExpr(3))
  ExpressionStmt:3(
    TupleExpr:3(
      NameExpr(x [__main__.x])
      NameExpr(y [__main__.y])
      NameExpr(z [__main__.z]))))

[case testEmptyFunction]
def f(): pass
f()
[out]
MypyFile:1(
  FuncDef:1(
    f
    Block:1(
      PassStmt:1()))
  ExpressionStmt:2(
    CallExpr:2(
      NameExpr(f [__main__.f])
      Args())))

[case testAccessingGlobalNameBeforeDefinition]
x
f()
x = 1
def f(): pass
[out]
MypyFile:1(
  ExpressionStmt:1(
    NameExpr(x [__main__.x]))
  ExpressionStmt:2(
    CallExpr:2(
      NameExpr(f [__main__.f])
      Args()))
  AssignmentStmt:3(
    NameExpr(x* [__main__.x])
    IntExpr(1))
  FuncDef:4(
    f
    Block:4(
      PassStmt:4())))

[case testFunctionArgs]
def f(x, y):
  (x, y)
[out]
MypyFile:1(
  FuncDef:1(
    f
    Args(
      Var(x)
      Var(y))
    Block:1(
      ExpressionStmt:2(
        TupleExpr:2(
          NameExpr(x [l])
          NameExpr(y [l]))))))

[case testLocalVar]
def f():
  x = 1
  x
[out]
MypyFile:1(
  FuncDef:1(
    f
    Block:1(
      AssignmentStmt:2(
        NameExpr(x* [l])
        IntExpr(1))
      ExpressionStmt:3(
        NameExpr(x [l])))))

[case testAccessGlobalInFn]
def f():
  x
  g()
x = 1
def g(): pass
[out]
MypyFile:1(
  FuncDef:1(
    f
    Block:1(
      ExpressionStmt:2(
        NameExpr(x [__main__.x]))
      ExpressionStmt:3(
        CallExpr:3(
          NameExpr(g [__main__.g])
          Args()))))
  AssignmentStmt:4(
    NameExpr(x* [__main__.x])
    IntExpr(1))
  FuncDef:5(
    g
    Block:5(
      PassStmt:5())))

[case testAssignmentAfterInit]
x = 1
x = 2
def f(y):
  y = 1
  z = 1
  z = 2
[out]
MypyFile:1(
  AssignmentStmt:1(
    NameExpr(x* [__main__.x])
    IntExpr(1))
  AssignmentStmt:2(
    NameExpr(x [__main__.x])
    IntExpr(2))
  FuncDef:3(
    f
    Args(
      Var(y))
    Block:3(
      AssignmentStmt:4(
        NameExpr(y [l])
        IntExpr(1))
      AssignmentStmt:5(
        NameExpr(z* [l])
        IntExpr(1))
      AssignmentStmt:6(
        NameExpr(z [l])
        IntExpr(2)))))

[case testLocalAndGlobalAliasing]
x = 1
def f():
  x = 2
  x
x
[out]
MypyFile:1(
  AssignmentStmt:1(
    NameExpr(x* [__main__.x])
    IntExpr(1))
  FuncDef:2(
    f
    Block:2(
      AssignmentStmt:3(
        NameExpr(x* [l])
        IntExpr(2))
      ExpressionStmt:4(
        NameExpr(x [l]))))
  ExpressionStmt:5(
    NameExpr(x [__main__.x])))

[case testArgumentInitializers]
def f(x = f, y = object):
  x, y
[out]
MypyFile:1(
  FuncDef:1(
    f
    Args(
      default(
        Var(x)
        NameExpr(f [__main__.f]))
      default(
        Var(y)
        NameExpr(object [builtins.object])))
    Block:1(
      ExpressionStmt:2(
        TupleExpr:2(
          NameExpr(x [l])
          NameExpr(y [l]))))))

[case testVarArgs]
def f(x, *y):
  x, y
[out]
MypyFile:1(
  FuncDef:1(
    f
    Args(
      Var(x))
    VarArg(
      Var(y))
    Block:1(
      ExpressionStmt:2(
        TupleExpr:2(
          NameExpr(x [l])
          NameExpr(y [l]))))))

[case testGlobalDecl]
x = None
def f():
    global x
    x = None
    x
class A: pass
[out]
MypyFile:1(
  AssignmentStmt:1(
    NameExpr(x* [__main__.x])
    NameExpr(None [builtins.None]))
  FuncDef:2(
    f
    Block:2(
      GlobalDecl:3(
        x)
      AssignmentStmt:4(
        NameExpr(x [__main__.x])
        NameExpr(None [builtins.None]))
      ExpressionStmt:5(
        NameExpr(x [__main__.x]))))
  ClassDef:6(
    A
    PassStmt:6()))

[case testMultipleNamesInGlobalDecl]
x, y = None, None
def f():
    global x, y
    x = y
[out]
MypyFile:1(
  AssignmentStmt:1(
    TupleExpr:1(
      NameExpr(x* [__main__.x])
      NameExpr(y* [__main__.y]))
    TupleExpr:1(
      NameExpr(None [builtins.None])
      NameExpr(None [builtins.None])))
  FuncDef:2(
    f
    Block:2(
      GlobalDecl:3(
        x
        y)
      AssignmentStmt:4(
        NameExpr(x [__main__.x])
        NameExpr(y [__main__.y])))))

[case testGlobalDeclScope]
x = None
def f():
    global x
def g():
    x = None
[out]
MypyFile:1(
  AssignmentStmt:1(
    NameExpr(x* [__main__.x])
    NameExpr(None [builtins.None]))
  FuncDef:2(
    f
    Block:2(
      GlobalDecl:3(
        x)))
  FuncDef:4(
    g
    Block:4(
      AssignmentStmt:5(
        NameExpr(x* [l])
        NameExpr(None [builtins.None])))))

[case testGlobalDeclScope]
x = None
def f():
    global x
def g():
    x = None
[out]
MypyFile:1(
  AssignmentStmt:1(
    NameExpr(x* [__main__.x])
    NameExpr(None [builtins.None]))
  FuncDef:2(
    f
    Block:2(
      GlobalDecl:3(
        x)))
  FuncDef:4(
    g
    Block:4(
      AssignmentStmt:5(
        NameExpr(x* [l])
        NameExpr(None [builtins.None])))))

[case testGlobaWithinMethod]
x = None
class A:
  def f(self):
    global x
    x = self
[out]
MypyFile:1(
  AssignmentStmt:1(
    NameExpr(x* [__main__.x])
    NameExpr(None [builtins.None]))
  ClassDef:2(
    A
    FuncDef:3(
      f
      Args(
        Var(self))
      Block:3(
        GlobalDecl:4(
          x)
        AssignmentStmt:5(
          NameExpr(x [__main__.x])
          NameExpr(self [l]))))))

[case testGlobalDefinedInBlock]
if object:
    x = object()
    x = x
x
[out]
MypyFile:1(
  IfStmt:1(
    If(
      NameExpr(object [builtins.object]))
    Then(
      AssignmentStmt:2(
        NameExpr(x* [__main__.x])
        CallExpr:2(
          NameExpr(object [builtins.object])
          Args()))
      AssignmentStmt:3(
        NameExpr(x [__main__.x])
        NameExpr(x [__main__.x]))))
  ExpressionStmt:4(
    NameExpr(x [__main__.x])))

[case testNonlocalDecl]
def g():
    x = None
    def f():
        nonlocal x
        x = None
        x
[out]
MypyFile:1(
  FuncDef:1(
    g
    Block:1(
      AssignmentStmt:2(
        NameExpr(x* [l])
        NameExpr(None [builtins.None]))
      FuncDef:3(
        f
        Block:3(
          NonlocalDecl:4(
            x)
          AssignmentStmt:5(
            NameExpr(x [l])
            NameExpr(None [builtins.None]))
          ExpressionStmt:6(
            NameExpr(x [l])))))))

[case testMultipleNamesInNonlocalDecl]
def g():
    x, y = None, None
    def f(z):
        nonlocal x, y
        x = y
[out]
MypyFile:1(
  FuncDef:1(
    g
    Block:1(
      AssignmentStmt:2(
        TupleExpr:2(
          NameExpr(x* [l])
          NameExpr(y* [l]))
        TupleExpr:2(
          NameExpr(None [builtins.None])
          NameExpr(None [builtins.None])))
      FuncDef:3(
        f
        Args(
          Var(z))
        Block:3(
          NonlocalDecl:4(
            x
            y)
          AssignmentStmt:5(
            NameExpr(x [l])
            NameExpr(y [l])))))))

[case testNestedFunctions]
def f(x):
    def g(y):
        z = y + x
    return g
[out]
MypyFile:1(
  FuncDef:1(
    f
    Args(
      Var(x))
    Block:1(
      FuncDef:2(
        g
        Args(
          Var(y))
        Block:2(
          AssignmentStmt:3(
            NameExpr(z* [l])
            OpExpr:3(
              +
              NameExpr(y [l])
              NameExpr(x [l])))))
      ReturnStmt:4(
        NameExpr(g [l])))))

[case testNestedFunctionWithOverlappingName]
def f(x):
    def g():
        x = 1
[out]
MypyFile:1(
  FuncDef:1(
    f
    Args(
      Var(x))
    Block:1(
      FuncDef:2(
        g
        Block:2(
          AssignmentStmt:3(
            NameExpr(x* [l])
            IntExpr(1)))))))
