[case testEmptyFile]
[out]

[case testSingleFunction]
def f():
    x = 1
[out]
def f() -> None: ...

[case testTwoFunctions]
def f(a, b):
    x = 1
def g(arg):
    pass
[out]
from typing import Any

def f(a: Any, b: Any) -> None: ...
def g(arg: Any) -> None: ...

[case testDefaultArgInt]
def f(a, b=2): ...
def g(b=-1, c=0): ...
[out]
from typing import Any

def f(a: Any, b: int = ...) -> None: ...
def g(b: int = ..., c: int = ...) -> None: ...

[case testDefaultArgNone]
def f(x=None): ...
[out]
from typing import Any, Optional

def f(x: Optional[Any] = ...) -> None: ...

[case testDefaultArgBool]
def f(x=True, y=False): ...
[out]
def f(x: bool = ..., y: bool = ...) -> None: ...

[case testDefaultArgStr]
def f(x='foo'): ...
[out]
def f(x: str = ...) -> None: ...

[case testDefaultArgBytes]
def f(x=b'foo'): ...
[out]
def f(x: bytes = ...) -> None: ...

[case testDefaultArgFloat]
def f(x=1.2): ...
[out]
def f(x: float = ...) -> None: ...

[case testDefaultArgOther]
def f(x=ord): ...
[out]
from typing import Any

def f(x: Any = ...) -> None: ...

[case testPreserveFunctionAnnotation]
def f(x: Foo) -> Bar: ...
[out]
def f(x: Foo) -> Bar: ...

[case testPreserveVarAnnotation]
x: Foo
[out]
x: Foo

[case testPreserveVarAnnotationWithoutQuotes]
x: 'Foo'
[out]
x: Foo

[case testVarArgs]
def f(x, *y): ...
[out]
from typing import Any

def f(x: Any, *y: Any) -> None: ...

[case testKwVarArgs]
def f(x, **y): ...
[out]
from typing import Any

def f(x: Any, **y: Any) -> None: ...

[case testVarArgsWithKwVarArgs]
def f(a, *b, **c): ...
def g(a, *b, c=1): ...
def h(a, *b, c=1, **d): ...
def i(a, *, b=1): ...
def j(a, *, b=1, **c): ...
[out]
from typing import Any

def f(a: Any, *b: Any, **c: Any) -> None: ...
def g(a: Any, *b: Any, c: int = ...) -> None: ...
def h(a: Any, *b: Any, c: int = ..., **d: Any) -> None: ...
def i(a: Any, *, b: int = ...) -> None: ...
def j(a: Any, *, b: int = ..., **c: Any) -> None: ...

[case testClass]
class A:
    def f(self, x):
        x = 1
def g(): ...
[out]
from typing import Any

class A:
    def f(self, x: Any) -> None: ...

def g() -> None: ...

[case testVariable]
x = 1
[out]
x: int

[case testAnnotatedVariable]
x: int = 1
[out]
x: int

[case testAnnotatedVariableGeneric]
x: Foo[int, str] = ...
[out]
x: Foo[int, str]

[case testAnnotatedVariableOldSyntax]
x = 1  # type: int
[out]
x: int

[case testAnnotatedVariableNone]
x: None
[out]
x: None

[case testAnnotatedVariableNoneOldSyntax]
x = None  # type: None
[out]
x: None

[case testMultipleVariable]
x = y = 1
[out]
x: int
y: int

[case testClassVariable]
class C:
    x = 1
[out]
class C:
    x: int = ...

[case testSelfAssignment]
class C:
    def __init__(self):
        self.x = 1
        x.y = 2
[out]
class C:
    x: int = ...
    def __init__(self) -> None: ...

[case testSelfAndClassBodyAssignment]
x = 1
class C:
    x = 1
    def __init__(self):
        self.x = 1
        self.x = 1
[out]
x: int

class C:
    x: int = ...
    def __init__(self) -> None: ...

[case testEmptyClass]
class A: ...
[out]
class A: ...

[case testSkipPrivateFunction]
def _f(): ...
def g(): ...
[out]
def g() -> None: ...

[case testIncludePrivateFunction]
# flags:  --include-private
def _f(): ...
def g(): ...
[out]
def _f() -> None: ...
def g() -> None: ...

[case testSkipPrivateMethod]
class A:
    def _f(self): ...
[out]
class A: ...

[case testIncludePrivateMethod]
# flags:  --include-private
class A:
    def _f(self): ...
[out]
class A:
    def _f(self) -> None: ...

[case testSkipPrivateVar]
_x = 1
class A:
    _y = 1
[out]
class A: ...

[case testIncludePrivateVar]
# flags:  --include-private
_x = 1
class A:
    _y = 1
[out]
_x: int

class A:
    _y: int = ...

[case testSpecialInternalVar]
__all__ = []
__author__ = ''
__version__ = ''
[out]

[case testBaseClass]
class A: ...
class B(A): ...
[out]
class A: ...
class B(A): ...

[case testDecoratedFunction]
@decorator
def foo(x): ...
[out]
from typing import Any

def foo(x: Any) -> None: ...

[case testMultipleAssignment]
x, y = 1, 2
[out]
from typing import Any

x: Any
y: Any

[case testMultipleAssignmentAnnotated]
x, y = 1, "2" # type: int, str
[out]
x: int
y: str

[case testMultipleAssignment2]
[x, y] = 1, 2
[out]
from typing import Any

x: Any
y: Any

[case testKeywordOnlyArg]
def f(x, *, y=1): ...
def g(x, *, y=1, z=2): ...
[out]
from typing import Any

def f(x: Any, *, y: int = ...) -> None: ...
def g(x: Any, *, y: int = ..., z: int = ...) -> None: ...

[case testProperty]
class A:
    @property
    def f(self):
        return 1
    @f.setter
    def f(self, x): ...
[out]
from typing import Any

class A:
    @property
    def f(self): ...
    @f.setter
    def f(self, x: Any) -> None: ...

[case testStaticMethod]
class A:
    @staticmethod
    def f(x): ...
[out]
from typing import Any

class A:
    @staticmethod
    def f(x: Any) -> None: ...

[case testClassMethod]
class A:
    @classmethod
    def f(cls): ...
[out]
class A:
    @classmethod
    def f(cls) -> None: ...

[case testIfMainCheck]
def a(): ...
if __name__ == '__main__':
    x = 1
    def f(): ...
def b(): ...
[out]
def a() -> None: ...
def b() -> None: ...

[case testImportStar]
from x import *
from a.b import *
def f(): ...
[out]
from x import *
from a.b import *

def f() -> None: ...

[case testNoSpacesBetweenEmptyClasses]
class X:
    def g(self): ...
class A: ...
class B: ...
class C:
    def f(self): ...
[out]
class X:
    def g(self) -> None: ...

class A: ...
class B: ...

class C:
    def f(self) -> None: ...

[case testExceptionBaseClasses]
class A(Exception): ...
class B(ValueError): ...
[out]
class A(Exception): ...
class B(ValueError): ...

[case testOmitSomeSpecialMethods]
class A:
    def __str__(self): ...
    def __repr__(self): ...
    def __eq__(self): ...
    def __getstate__(self): ...
    def __setstate__(self, state): ...
[out]
class A:
    def __eq__(self) -> None: ...

[case testOmitDefsNotInAll_import]
__all__ = [] + ['f']
def f(): ...
def g(): ...
[out]
def f() -> None: ...

[case testVarDefsNotInAll_import]
__all__ = [] + ['f', 'g']
def f(): ...
x = 1
y = 1
def g(): ...
[out]
def f() -> None: ...
def g() -> None: ...

[case testIncludeClassNotInAll_import]
__all__ = [] + ['f']
def f(): ...
class A: ...
[out]
def f() -> None: ...

class A: ...

[case testAllAndClass_import]
__all__ = ['A']
class A:
    x = 1
    def f(self): ...
[out]
class A:
    x: int = ...
    def f(self) -> None: ...

[case testSkipMultiplePrivateDefs]
class A: ...
_x = 1
_y = 1
_z = 1
class C: ...
[out]
class A: ...
class C: ...

[case testIncludeMultiplePrivateDefs]
# flags:  --include-private
class A: ...
_x = 1
_y = 1
_z = 1
class C: ...
[out]
class A: ...

_x: int
_y: int
_z: int

class C: ...

[case testIncludeFromImportIfInAll_import]
from re import match, search, sub
__all__ = ['match', 'sub', 'x']
x = 1
[out]
from re import match as match, sub as sub

x: int

[case testExportModule_import]
import re
__all__ = ['re', 'x']
x = 1
y = 2
[out]
import re as re

x: int

[case testExportModule_import]
import re
__all__ = ['re', 'x']
x = 1
y = 2
[out]
import re as re

x: int

[case testExportModuleAs_import]
import re as rex
__all__ = ['rex', 'x']
x = 1
y = 2
[out]
import re as rex

x: int

[case testExportModuleInPackage_import]
import urllib.parse as p
__all__ = ['p']
[out]
import urllib.parse as p

[case testExportPackageOfAModule_import]
import urllib.parse
__all__ = ['urllib']

[out]
import urllib as urllib

[case testRelativeImportAll]
from .x import *
[out]
from .x import *

[case testCommentForUndefinedName_import]
__all__ = ['f', 'x', 'C', 'g']
def f(): ...
x = 1
class C:
    def g(self): ...
[out]
def f() -> None: ...

x: int

class C:
    def g(self) -> None: ...

# Names in __all__ with no definition:
#   g

[case testIgnoreSlots]
class A:
    __slots__ = ()
[out]
class A: ...

[case testSkipPrivateProperty]
class A:
    @property
    def _foo(self): ...
[out]
class A: ...

[case testIncludePrivateProperty]
# flags:  --include-private
class A:
    @property
    def _foo(self): ...
[out]
class A:
    @property
    def _foo(self) -> None: ...

[case testSkipPrivateStaticAndClassMethod]
class A:
    @staticmethod
    def _foo(): ...
    @classmethod
    def _bar(cls): ...
[out]
class A: ...

[case testIncludePrivateStaticAndClassMethod]
# flags:  --include-private
class A:
    @staticmethod
    def _foo(): ...
    @classmethod
    def _bar(cls): ...
[out]
class A:
    @staticmethod
    def _foo() -> None: ...
    @classmethod
    def _bar(cls) -> None: ...

[case testNamedtuple]
import collections, x
X = collections.namedtuple('X', ['a', 'b'])
[out]
from collections import namedtuple

X = namedtuple('X', ['a', 'b'])

[case testNamedtupleAltSyntax]
from collections import namedtuple, x
X = namedtuple('X', 'a b')
[out]
from collections import namedtuple

X = namedtuple('X', 'a b')

[case testNamedtupleWithUnderscore]
from collections import namedtuple as _namedtuple
def f(): ...
X = _namedtuple('X', 'a b')
def g(): ...
[out]
from collections import namedtuple

def f() -> None: ...

X = namedtuple('X', 'a b')

def g() -> None: ...

[case testNamedtupleBaseClass]
import collections, x
_X = collections.namedtuple('_X', ['a', 'b'])
class Y(_X): ...
[out]
from collections import namedtuple

_X = namedtuple('_X', ['a', 'b'])

class Y(_X): ...

[case testNamedtupleAltSyntaxFieldsTuples]
from collections import namedtuple, x
X = namedtuple('X', ())
Y = namedtuple('Y', ('a',))
Z = namedtuple('Z', ('a', 'b', 'c', 'd', 'e'))
[out]
from collections import namedtuple

X = namedtuple('X', [])

Y = namedtuple('Y', ['a'])

Z = namedtuple('Z', ['a', 'b', 'c', 'd', 'e'])

[case testArbitraryBaseClass]
import x
class D(x.C): ...
[out]
import x

class D(x.C): ...

[case testArbitraryBaseClass]
import x.y
class D(x.y.C): ...
[out]
import x.y

class D(x.y.C): ...

[case testUnqualifiedArbitraryBaseClassWithNoDef]
class A(int): ...
[out]
class A(int): ...

[case testUnqualifiedArbitraryBaseClass]
from x import X
class A(X): ...
[out]
from x import X

class A(X): ...

[case testUnqualifiedArbitraryBaseClassWithImportAs]
from x import X as _X
class A(_X): ...
[out]
from x import X as _X

class A(_X): ...

[case testGenericClass]
class D(Generic[T]): ...
[out]
class D(Generic[T]): ...

[case testObjectBaseClass]
class A(object): ...
[out]
class A: ...

[case testEmptyLines]
def x(): ...
def f():
    class A:
        def f(self):
            self.x = 1
def g(): ...
[out]
def x() -> None: ...
def f() -> None: ...
def g() -> None: ...

[case testNestedClass]
class A:
    class B:
        x = 1
        def f(self): ...
    def g(self): ...
[out]
class A:
    class B:
        x: int = ...
        def f(self) -> None: ...
    def g(self) -> None: ...

[case testExportViaRelativeImport]
from .api import get
[out]
from .api import get

[case testExportViaRelativePackageImport]
from .packages.urllib3.contrib import parse
[out]
from .packages.urllib3.contrib import parse

[case testNoExportViaRelativeImport]
from . import get
[out]

[case testRelativeImportAndBase]
from .x import X
class A(X):
     pass
[out]
from .x import X

class A(X): ...

[case testDuplicateDef]
def syslog(a): pass
def syslog(a): pass
[out]
from typing import Any

def syslog(a: Any) -> None: ...

[case testAsyncAwait_fast_parser]
async def f(a):
   x = await y
[out]
from typing import Any

def f(a: Any) -> None: ...

[case testInferOptionalOnlyFunc]
class A:
    x = None
    def __init__(self, a=None):
        self.x = []
    def method(self, a=None):
        self.x = []
[out]
from typing import Any, Optional

class A:
    x: Any = ...
    def __init__(self, a: Optional[Any] = ...) -> None: ...
    def method(self, a: Optional[Any] = ...) -> None: ...

[case testAnnotationImportsFrom]
import foo
from collection import defaultdict
x: defaultdict

[out]
from collection import defaultdict

x: defaultdict

[case testAnnotationImports]
import foo
import collection
x: collection.defaultdict

[out]
import collection

x: collection.defaultdict


[case testAnnotationImports]
from typing import List
import collection
x: List[collection.defaultdict]

[out]
import collection
from typing import List

x: List[collection.defaultdict]


[case testAnnotationFwRefs]
x: C

class C:
    attr: C

y: C
[out]
x: C

class C:
    attr: C

y: C

[case testTypeVarPreserved]
tv = TypeVar('tv')

[out]
from typing import TypeVar

tv = TypeVar('tv')

[case testTypeVarArgsPreserved]
tv = TypeVar('tv', int, str)

[out]
from typing import TypeVar

tv = TypeVar('tv', int, str)

[case testTypeVarNamedArgsPreserved]
tv = TypeVar('tv', bound=bool, covariant=True)

[out]
from typing import TypeVar

tv = TypeVar('tv', bound=bool, covariant=True)

[case testTypeAliasPreserved]
alias = str

[out]
alias = str

[case testDeepTypeAliasPreserved]

alias = Dict[str, List[str]]

[out]
alias = Dict[str, List[str]]

[case testDeepGenericTypeAliasPreserved]
from typing import TypeVar

T = TypeVar('T')
alias = Union[T, List[T]]

[out]
from typing import TypeVar

T = TypeVar('T')
alias = Union[T, List[T]]

[case testEllipsisAliasPreserved]

alias = Tuple[int, ...]

[out]
alias = Tuple[int, ...]

[case testCallableAliasPreserved]

alias1 = Callable[..., int]
alias2 = Callable[[str, bool], None]

[out]
alias1 = Callable[..., int]
alias2 = Callable[[str, bool], None]

[case testAliasPullsImport]
from module import Container

alias = Container[Any]

[out]
from module import Container
from typing import Any

alias = Container[Any]

[case testAliasOnlyToplevel]
class Foo:
    alias = str

[out]
from typing import Any

class Foo:
    alias: Any = ...

[case testAliasExceptions]
noalias1 = None
noalias2 = ...
noalias3 = True

[out]
from typing import Any

noalias1: Any
noalias2: Any
noalias3: bool

-- More features/fixes:
--   do not export deleted names

[case testFunctionNoReturnInfersReturnNone]
def f():
    x = 1
[out]
def f() -> None: ...

[case testFunctionReturnNoReturnType]
def f():
    return 1
def g():
    return
[out]
def f(): ...
def g(): ...

[case testFunctionEllipsisInfersReturnNone]
def f(): ...
[out]
def f() -> None: ...

[case testCallable]
from typing import Callable

x: Callable[[int, int], int]
[out]
from typing import Callable

x: Callable[[int, int], int]
