| [case testEmptyFile] |
| [out] |
| |
| [case testSingleFunction] |
| def f(): |
| x = 1 |
| [out] |
| def f(): ... |
| |
| [case testTwoFunctions] |
| def f(a, b): |
| x = 1 |
| def g(arg): |
| pass |
| [out] |
| def f(a, b): ... |
| def g(arg): ... |
| |
| [case testDefaultArgInt] |
| def f(a, b=2): ... |
| def g(b=-1, c=0): ... |
| [out] |
| def f(a, b: int = ...): ... |
| def g(b: int = ..., c: int = ...): ... |
| |
| [case testDefaultArgNone] |
| def f(x=None): ... |
| [out] |
| from typing import Any, Optional |
| |
| def f(x: Optional[Any] = ...): ... |
| |
| [case testDefaultArgBool] |
| def f(x=True, y=False): ... |
| [out] |
| def f(x: bool = ..., y: bool = ...): ... |
| |
| [case testDefaultArgStr] |
| def f(x='foo'): ... |
| [out] |
| def f(x: str = ...): ... |
| |
| [case testDefaultArgBytes] |
| def f(x=b'foo'): ... |
| [out] |
| def f(x: bytes = ...): ... |
| |
| [case testDefaultArgFloat] |
| def f(x=1.2): ... |
| [out] |
| def f(x: float = ...): ... |
| |
| [case testDefaultArgOther] |
| def f(x=ord): ... |
| [out] |
| from typing import Any |
| |
| def f(x: Any = ...): ... |
| |
| [case testVarArgs] |
| def f(x, *y): ... |
| [out] |
| def f(x, *y): ... |
| |
| [case testKwVarArgs] |
| def f(x, **y): ... |
| [out] |
| def f(x, **y): ... |
| |
| [case testClass] |
| class A: |
| def f(self, x): |
| x = 1 |
| def g(): ... |
| [out] |
| class A: |
| def f(self, x): ... |
| |
| def g(): ... |
| |
| [case testVariable] |
| x = 1 |
| [out] |
| x = ... # type: int |
| |
| [case testMultipleVariable] |
| x = y = 1 |
| [out] |
| x = ... # type: int |
| y = ... # type: int |
| |
| [case testClassVariable] |
| class C: |
| x = 1 |
| [out] |
| class C: |
| x = ... # type: int |
| |
| [case testSelfAssignment] |
| class C: |
| def __init__(self): |
| self.x = 1 |
| x.y = 2 |
| [out] |
| class C: |
| x = ... # type: int |
| def __init__(self) -> None: ... |
| |
| [case testSelfAndClassBodyAssignment] |
| x = 1 |
| class C: |
| x = 1 |
| def __init__(self): |
| self.x = 1 |
| self.x = 1 |
| [out] |
| x = ... # type: int |
| |
| class C: |
| x = ... # type: int |
| def __init__(self) -> None: ... |
| |
| [case testEmptyClass] |
| class A: ... |
| [out] |
| class A: ... |
| |
| [case testPrivateFunction] |
| def _f(): ... |
| def g(): ... |
| [out] |
| def g(): ... |
| |
| [case testPrivateMethod] |
| class A: |
| def _f(self): ... |
| [out] |
| class A: ... |
| |
| [case testPrivateVar] |
| _x = 1 |
| class A: |
| _y = 1 |
| [out] |
| class A: ... |
| |
| [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] |
| def foo(x): ... |
| |
| [case testMultipleAssignment] |
| x, y = 1, 2 |
| [out] |
| from typing import Any |
| |
| x = ... # type: Any |
| y = ... # type: Any |
| |
| [case testMultipleAssignment2] |
| [x, y] = 1, 2 |
| [out] |
| from typing import Any |
| |
| x = ... # type: Any |
| y = ... # type: Any |
| |
| [case testKeywordOnlyArg] |
| def f(x, *, y=1): ... |
| def g(x, *, y=1, z=2): ... |
| [out] |
| def f(x, *, y: int = ...): ... |
| def g(x, *, y: int = ..., z: int = ...): ... |
| |
| [case testProperty] |
| class A: |
| @property |
| def f(self): |
| return 1 |
| @f.setter |
| def f(self, x): ... |
| [out] |
| class A: |
| @property |
| def f(self): ... |
| @f.setter |
| def f(self, x): ... |
| |
| [case testStaticMethod] |
| class A: |
| @staticmethod |
| def f(x): ... |
| [out] |
| class A: |
| @staticmethod |
| def f(x): ... |
| |
| [case testClassMethod] |
| class A: |
| @classmethod |
| def f(cls): ... |
| [out] |
| class A: |
| @classmethod |
| def f(cls): ... |
| |
| [case testIfMainCheck] |
| def a(): ... |
| if __name__ == '__main__': |
| x = 1 |
| def f(): ... |
| def b(): ... |
| [out] |
| def a(): ... |
| def b(): ... |
| |
| [case testImportStar] |
| from x import * |
| from a.b import * |
| def f(): ... |
| [out] |
| from x import * |
| from a.b import * |
| |
| def f(): ... |
| |
| [case testNoSpacesBetweenEmptyClasses] |
| class X: |
| def g(self): ... |
| class A: ... |
| class B: ... |
| class C: |
| def f(self): ... |
| [out] |
| class X: |
| def g(self): ... |
| |
| class A: ... |
| class B: ... |
| |
| class C: |
| def f(self): ... |
| |
| [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): ... |
| |
| [case testOmitDefsNotInAll_import] |
| __all__ = [] + ['f'] |
| def f(): ... |
| def g(): ... |
| [out] |
| def f(): ... |
| |
| [case testVarDefsNotInAll_import] |
| __all__ = [] + ['f', 'g'] |
| def f(): ... |
| x = 1 |
| y = 1 |
| def g(): ... |
| [out] |
| def f(): ... |
| def g(): ... |
| |
| [case testIncludeClassNotInAll_import] |
| __all__ = [] + ['f'] |
| def f(): ... |
| class A: ... |
| [out] |
| def f(): ... |
| |
| class A: ... |
| |
| [case testAllAndClass_import] |
| __all__ = ['A'] |
| class A: |
| x = 1 |
| def f(self): ... |
| [out] |
| class A: |
| x = ... # type: int |
| def f(self): ... |
| |
| [case testMultiplePrivateDefs] |
| class A: ... |
| _x = 1 |
| _y = 1 |
| _z = 1 |
| class C: ... |
| [out] |
| class A: ... |
| 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 = ... # type: int |
| |
| [case testExportModule_import] |
| import re |
| __all__ = ['re', 'x'] |
| x = 1 |
| y = 2 |
| [out] |
| import re as re |
| |
| x = ... # type: int |
| |
| [case testExportModuleAs_import] |
| import re as rex |
| __all__ = ['rex', 'x'] |
| x = 1 |
| y = 2 |
| [out] |
| import re as rex |
| |
| x = ... # type: int |
| |
| [case testExportModuleInPackage_import] |
| import urllib.parse as p |
| __all__ = ['p'] |
| [out] |
| import urllib.parse as p |
| |
| [case testExportModuleInPackageUnsupported_import] |
| import urllib.parse |
| __all__ = ['urllib'] |
| [out] |
| # Names in __all__ with no definition: |
| # 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(): ... |
| |
| x = ... # type: int |
| |
| class C: |
| def g(self): ... |
| |
| # 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 testSkipPrivateStaticAndClassMethod] |
| class A: |
| @staticmethod |
| def _foo(): ... |
| @classmethod |
| def _bar(cls): ... |
| [out] |
| class A: ... |
| |
| [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 as _namedtuple |
| from collections import namedtuple |
| |
| def f(): ... |
| |
| X = namedtuple('X', 'a b') |
| |
| def g(): ... |
| |
| [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 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 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(): ... |
| def f(): ... |
| def g(): ... |
| |
| [case testNestedClass] |
| class A: |
| class B: |
| x = 1 |
| def f(self): ... |
| def g(self): ... |
| [out] |
| class A: |
| class B: |
| x = ... # type: int |
| def f(self): ... |
| def g(self): ... |
| |
| [case testExportViaRelativeImport] |
| from .api import get |
| [out] |
| from .api import get as get |
| |
| [case testExportViaRelativePackageImport] |
| from .packages.urllib3.contrib import parse |
| [out] |
| from .packages.urllib3.contrib import parse as parse |
| |
| [case testNoExportViaRelativeImport] |
| from . import get |
| [out] |
| |
| [case testRelativeImportAndBase] |
| from .x import X |
| class A(X): |
| pass |
| [out] |
| from .x import X as X |
| |
| class A(X): ... |
| |
| [case testDuplicateDef] |
| def syslog(a): pass |
| def syslog(a): pass |
| [out] |
| def syslog(a): ... |
| |
| [case testAsyncAwait_fast_parser] |
| async def f(a): |
| x = await y |
| [out] |
| def f(a): ... |
| |
| [case testInferOptionalOnlyFunc] |
| class A: |
| x = None |
| def __init__(self, a=None) -> None: |
| self.x = [] |
| [out] |
| from typing import Any, Optional |
| |
| class A: |
| x = ... # type: Any |
| def __init__(self, a: Optional[Any] = ...) -> None: ... |
| |
| -- More features/fixes: |
| -- do not export deleted names |