From 076d61b7bd27160de03098f40ccccb8eeb1692d5 Mon Sep 17 00:00:00 2001 From: Steven Troxler Date: Wed, 18 Aug 2021 09:37:35 -0400 Subject: [PATCH] The ufmt tool combines usort and black with a consistent wrapper, which ensures we won't have inconsistent black-vs-isort errors going forward. We can always format by running `ufmt format .` at the root, and check with `ufmt check .` in our CI actions. --- .github/workflows/build.yml | 3 +-- CONTRIBUTING.md | 2 +- README.rst | 4 ++-- docs/source/tutorial.ipynb | 2 +- libcst/__init__.py | 2 -- libcst/_add_slots.py | 1 - libcst/_batched_visitor.py | 1 - libcst/_exceptions.py | 1 - libcst/_flatten_sentinel.py | 1 - libcst/_metadata_dependent.py | 1 - libcst/_nodes/base.py | 1 - libcst/_nodes/internal.py | 1 - libcst/_nodes/module.py | 1 - libcst/_nodes/statement.py | 1 - libcst/_nodes/tests/test_cst_node.py | 1 - libcst/_nodes/whitespace.py | 1 - libcst/_parser/base_parser.py | 1 - libcst/_parser/conversions/expression.py | 1 - libcst/_parser/conversions/statement.py | 1 - libcst/_parser/custom_itertools.py | 1 - libcst/_parser/detect_config.py | 1 - libcst/_parser/entrypoints.py | 1 - libcst/_parser/grammar.py | 1 - libcst/_parser/parso/pgen2/generator.py | 1 - libcst/_parser/parso/python/tokenize.py | 1 - libcst/_parser/parso/tests/test_tokenize.py | 1 - libcst/_parser/parso/utils.py | 1 - libcst/_parser/production_decorator.py | 1 - .../_parser/tests/test_whitespace_parser.py | 1 - libcst/_parser/tests/test_wrapped_tokenize.py | 1 - libcst/_parser/types/config.py | 1 - libcst/_parser/types/conversions.py | 1 - libcst/_parser/types/partials.py | 1 - libcst/_parser/whitespace_parser.py | 1 - libcst/_parser/wrapped_tokenize.py | 1 - libcst/_position.py | 1 - libcst/_type_enforce.py | 1 - libcst/_typed_visitor.py | 8 ++++---- libcst/_typed_visitor_base.py | 1 - libcst/_types.py | 1 - libcst/_visitors.py | 1 - libcst/codegen/gen_matcher_classes.py | 1 - libcst/codegen/gen_type_mapping.py | 1 - libcst/codegen/gen_visitor_functions.py | 1 - libcst/codegen/generate.py | 3 +-- libcst/codemod/__init__.py | 1 - libcst/codemod/_cli.py | 1 - libcst/codemod/_command.py | 1 - libcst/codemod/_dummy_pool.py | 1 - libcst/codemod/_runner.py | 1 - .../convert_percent_format_to_fstring.py | 1 - .../codemod/commands/remove_unused_imports.py | 1 - libcst/codemod/visitors/__init__.py | 1 - .../_gather_string_annotation_names.py | 1 - .../visitors/_gather_unused_imports.py | 1 - libcst/helpers/__init__.py | 1 - libcst/helpers/_template.py | 1 - libcst/matchers/__init__.py | 20 +++++++++---------- libcst/matchers/_decorators.py | 1 - libcst/matchers/_return_types.py | 6 +++--- libcst/matchers/_visitors.py | 1 - libcst/metadata/__init__.py | 1 - libcst/metadata/base_provider.py | 1 - libcst/metadata/full_repo_manager.py | 1 - libcst/metadata/position_provider.py | 1 - libcst/metadata/scope_provider.py | 1 - .../metadata/tests/test_full_repo_manager.py | 1 - libcst/metadata/wrapper.py | 1 - libcst/testing/utils.py | 1 - libcst/tests/test_fuzz.py | 1 - libcst/tests/test_pyre_integration.py | 1 - libcst/tests/test_type_enforce.py | 1 - libcst/tool.py | 1 - pyproject.toml | 8 -------- requirements-dev.txt | 9 +++++---- setup.py | 1 - stubs/tokenize.pyi | 1 - tox.ini | 6 ++---- 78 files changed, 30 insertions(+), 109 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 459206149..71b9f4054 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -69,8 +69,7 @@ jobs: if: steps.cache.outputs.cache-hit != 'true' run: exit 1 - run: flake8 - - run: isort --check-only . - - run: black --check libcst/ + - run: ufmt check . - run: python3 -m fixit.cli.run_rules # Run pyre typechecker diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 41a47707e..f8eab9f00 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -31,7 +31,7 @@ disclosure of security bugs. In those cases, please go through the process outlined on that page and do not file a public issue. ## Coding Style -We use flake8, isort and black to enforce coding style. +We use flake8 and ufmt to enforce coding style. ## License By contributing to LibCST, you agree that your contributions will be licensed diff --git a/README.rst b/README.rst index 3e563a2ff..b603be9c2 100644 --- a/README.rst +++ b/README.rst @@ -150,8 +150,8 @@ Start by setting up and activating a virtualenv: # If you're done with the virtualenv, you can leave it by running: deactivate -We use `isort `_ and `black `_ -to format code. To format changes to be conformant, run the following in the root: +We use `ufmt `_ to format code. To format +changes to be conformant, run the following in the root: .. code-block:: shell diff --git a/docs/source/tutorial.ipynb b/docs/source/tutorial.ipynb index 1fe570709..29e598084 100644 --- a/docs/source/tutorial.ipynb +++ b/docs/source/tutorial.ipynb @@ -186,7 +186,7 @@ "source": [ "Generate Source Code\n", "====================\n", - "Generating the source code from a cst tree is as easy as accessing the :attr:`~libcst.Module.code` attribute on :class:`~libcst.Module`. After the code generation, we often use `Black `_ and `isort `_ to reformate the code to keep a consistent coding style." + "Generating the source code from a cst tree is as easy as accessing the :attr:`~libcst.Module.code` attribute on :class:`~libcst.Module`. After the code generation, we often use `ufmt `_ to reformate the code to keep a consistent coding style." ] }, { diff --git a/libcst/__init__.py b/libcst/__init__.py index 8d9210e5b..01c1850ca 100644 --- a/libcst/__init__.py +++ b/libcst/__init__.py @@ -192,7 +192,6 @@ from libcst._removal_sentinel import RemovalSentinel, RemoveFromParent from libcst._visitors import CSTNodeT, CSTTransformer, CSTVisitor, CSTVisitorT - try: from libcst._version import version as LIBCST_VERSION except ImportError: @@ -207,7 +206,6 @@ ) from libcst.metadata.wrapper import MetadataWrapper - __all__ = [ "KNOWN_PYTHON_VERSION_STRINGS", "LIBCST_VERSION", diff --git a/libcst/_add_slots.py b/libcst/_add_slots.py index 706f5d10c..a62b2f2df 100644 --- a/libcst/_add_slots.py +++ b/libcst/_add_slots.py @@ -5,7 +5,6 @@ import dataclasses from typing import Any, Mapping, Type, TypeVar - _T = TypeVar("_T") diff --git a/libcst/_batched_visitor.py b/libcst/_batched_visitor.py index 9264c4c9c..683401083 100644 --- a/libcst/_batched_visitor.py +++ b/libcst/_batched_visitor.py @@ -19,7 +19,6 @@ from libcst._typed_visitor import CSTTypedVisitorFunctions from libcst._visitors import CSTNodeT, CSTVisitor - if TYPE_CHECKING: from libcst._nodes.base import CSTNode # noqa: F401 diff --git a/libcst/_exceptions.py b/libcst/_exceptions.py index fe41f0eee..1e84aab06 100644 --- a/libcst/_exceptions.py +++ b/libcst/_exceptions.py @@ -13,7 +13,6 @@ from libcst._parser.types.token import Token from libcst._tabs import expand_tabs - _EOF_STR: str = "end of file (EOF)" _INDENT_STR: str = "an indent" _DEDENT_STR: str = "a dedent" diff --git a/libcst/_flatten_sentinel.py b/libcst/_flatten_sentinel.py index 181480775..448650501 100644 --- a/libcst/_flatten_sentinel.py +++ b/libcst/_flatten_sentinel.py @@ -5,7 +5,6 @@ import sys - # PEP 585 if sys.version_info < (3, 9): from typing import Iterable, Sequence diff --git a/libcst/_metadata_dependent.py b/libcst/_metadata_dependent.py index c16277135..604230172 100644 --- a/libcst/_metadata_dependent.py +++ b/libcst/_metadata_dependent.py @@ -17,7 +17,6 @@ cast, ) - if TYPE_CHECKING: # Circular dependency for typing reasons only from libcst._nodes.base import CSTNode # noqa: F401 diff --git a/libcst/_nodes/base.py b/libcst/_nodes/base.py index 47bf26eae..a1f659d98 100644 --- a/libcst/_nodes/base.py +++ b/libcst/_nodes/base.py @@ -15,7 +15,6 @@ from libcst._types import CSTNodeT from libcst._visitors import CSTTransformer, CSTVisitor, CSTVisitorT - _CSTNodeSelfT = TypeVar("_CSTNodeSelfT", bound="CSTNode") _EMPTY_SEQUENCE: Sequence["CSTNode"] = () diff --git a/libcst/_nodes/internal.py b/libcst/_nodes/internal.py index 5bbefc010..b8294fb6c 100644 --- a/libcst/_nodes/internal.py +++ b/libcst/_nodes/internal.py @@ -14,7 +14,6 @@ from libcst._removal_sentinel import RemovalSentinel from libcst._types import CSTNodeT - if TYPE_CHECKING: # These are circular dependencies only used for typing purposes from libcst._nodes.base import CSTNode # noqa: F401 diff --git a/libcst/_nodes/module.py b/libcst/_nodes/module.py index 59a4507d8..2bd260166 100644 --- a/libcst/_nodes/module.py +++ b/libcst/_nodes/module.py @@ -18,7 +18,6 @@ from libcst._removal_sentinel import RemovalSentinel from libcst._visitors import CSTVisitorT - if TYPE_CHECKING: # This is circular, so import the type only in type checking from libcst._parser.types.config import PartialParserConfig diff --git a/libcst/_nodes/statement.py b/libcst/_nodes/statement.py index 6a831b85b..5e8068ee1 100644 --- a/libcst/_nodes/statement.py +++ b/libcst/_nodes/statement.py @@ -49,7 +49,6 @@ ) from libcst._visitors import CSTVisitorT - _INDENT_WHITESPACE_RE: Pattern[str] = re.compile(r"[ \f\t]+", re.UNICODE) diff --git a/libcst/_nodes/tests/test_cst_node.py b/libcst/_nodes/tests/test_cst_node.py index e3cb7e9ae..15f0f7ab7 100644 --- a/libcst/_nodes/tests/test_cst_node.py +++ b/libcst/_nodes/tests/test_cst_node.py @@ -12,7 +12,6 @@ from libcst._visitors import CSTTransformer from libcst.testing.utils import UnitTest, data_provider, none_throws - _EMPTY_SIMPLE_WHITESPACE = cst.SimpleWhitespace("") diff --git a/libcst/_nodes/whitespace.py b/libcst/_nodes/whitespace.py index 22182ebe7..e16eea431 100644 --- a/libcst/_nodes/whitespace.py +++ b/libcst/_nodes/whitespace.py @@ -19,7 +19,6 @@ ) from libcst._visitors import CSTVisitorT - # SimpleWhitespace includes continuation characters, which must be followed immediately # by a newline. SimpleWhitespace does not include other kinds of newlines, because those # may have semantic significance. diff --git a/libcst/_parser/base_parser.py b/libcst/_parser/base_parser.py index dc7f75ee0..35dafba44 100644 --- a/libcst/_parser/base_parser.py +++ b/libcst/_parser/base_parser.py @@ -36,7 +36,6 @@ from libcst._parser.parso.python.token import TokenType from libcst._parser.types.token import Token - _NodeT = TypeVar("_NodeT") _TokenTypeT = TypeVar("_TokenTypeT", bound=TokenType) _TokenT = TypeVar("_TokenT", bound=Token) diff --git a/libcst/_parser/conversions/expression.py b/libcst/_parser/conversions/expression.py index aa84a4e14..59f2defa1 100644 --- a/libcst/_parser/conversions/expression.py +++ b/libcst/_parser/conversions/expression.py @@ -121,7 +121,6 @@ from libcst._parser.types.token import Token from libcst._parser.whitespace_parser import parse_parenthesizable_whitespace - BINOP_TOKEN_LUT: typing.Dict[str, typing.Type[BaseBinaryOp]] = { "*": Multiply, "@": MatrixMultiply, diff --git a/libcst/_parser/conversions/statement.py b/libcst/_parser/conversions/statement.py index 8ff7ac8fe..ae0b1d17b 100644 --- a/libcst/_parser/conversions/statement.py +++ b/libcst/_parser/conversions/statement.py @@ -101,7 +101,6 @@ parse_simple_whitespace, ) - AUGOP_TOKEN_LUT: Dict[str, Type[BaseAugOp]] = { "+=": AddAssign, "-=": SubtractAssign, diff --git a/libcst/_parser/custom_itertools.py b/libcst/_parser/custom_itertools.py index ccbb1a1f0..867c934e6 100644 --- a/libcst/_parser/custom_itertools.py +++ b/libcst/_parser/custom_itertools.py @@ -6,7 +6,6 @@ from itertools import zip_longest from typing import Iterable, Iterator, TypeVar - _T = TypeVar("_T") diff --git a/libcst/_parser/detect_config.py b/libcst/_parser/detect_config.py index 0209d0a2b..ca13e7c22 100644 --- a/libcst/_parser/detect_config.py +++ b/libcst/_parser/detect_config.py @@ -18,7 +18,6 @@ from libcst._parser.types.token import Token from libcst._parser.wrapped_tokenize import tokenize_lines - _INDENT: TokenType = PythonTokenTypes.INDENT _NAME: TokenType = PythonTokenTypes.NAME _NEWLINE: TokenType = PythonTokenTypes.NEWLINE diff --git a/libcst/_parser/entrypoints.py b/libcst/_parser/entrypoints.py index 1a27e976b..f9e78ad89 100644 --- a/libcst/_parser/entrypoints.py +++ b/libcst/_parser/entrypoints.py @@ -20,7 +20,6 @@ from libcst._parser.python_parser import PythonCSTParser from libcst._parser.types.config import PartialParserConfig - _DEFAULT_PARTIAL_PARSER_CONFIG: PartialParserConfig = PartialParserConfig() diff --git a/libcst/_parser/grammar.py b/libcst/_parser/grammar.py index c8c240257..b86483c04 100644 --- a/libcst/_parser/grammar.py +++ b/libcst/_parser/grammar.py @@ -141,7 +141,6 @@ from libcst._parser.types.conversions import NonterminalConversion, TerminalConversion from libcst._parser.types.production import Production - # Keep this sorted alphabetically _TERMINAL_CONVERSIONS_SEQUENCE: Tuple[TerminalConversion, ...] = ( convert_DEDENT, diff --git a/libcst/_parser/parso/pgen2/generator.py b/libcst/_parser/parso/pgen2/generator.py index 546cc85f0..4e20e89d7 100644 --- a/libcst/_parser/parso/pgen2/generator.py +++ b/libcst/_parser/parso/pgen2/generator.py @@ -39,7 +39,6 @@ from libcst._parser.parso.pgen2.grammar_parser import GrammarParser, NFAState - _TokenTypeT = TypeVar("_TokenTypeT") diff --git a/libcst/_parser/parso/python/tokenize.py b/libcst/_parser/parso/python/tokenize.py index 6b30c6d09..e816cd62d 100644 --- a/libcst/_parser/parso/python/tokenize.py +++ b/libcst/_parser/parso/python/tokenize.py @@ -39,7 +39,6 @@ from libcst._parser.parso.python.token import PythonTokenTypes from libcst._parser.parso.utils import PythonVersionInfo, split_lines - # Maximum code point of Unicode 6.0: 0x10ffff (1,114,111) MAX_UNICODE = "\U0010ffff" BOM_UTF8_STRING = BOM_UTF8.decode("utf-8") diff --git a/libcst/_parser/parso/tests/test_tokenize.py b/libcst/_parser/parso/tests/test_tokenize.py index f2c62d338..d0834ad72 100644 --- a/libcst/_parser/parso/tests/test_tokenize.py +++ b/libcst/_parser/parso/tests/test_tokenize.py @@ -22,7 +22,6 @@ from libcst._parser.parso.utils import parse_version_string, split_lines from libcst.testing.utils import UnitTest, data_provider - # To make it easier to access some of the token types, just put them here. NAME = PythonTokenTypes.NAME NEWLINE = PythonTokenTypes.NEWLINE diff --git a/libcst/_parser/parso/utils.py b/libcst/_parser/parso/utils.py index 27b937319..0e4b49492 100644 --- a/libcst/_parser/parso/utils.py +++ b/libcst/_parser/parso/utils.py @@ -23,7 +23,6 @@ from dataclasses import dataclass from typing import Optional, Sequence, Tuple, Union - # The following is a list in Python that are line breaks in str.splitlines, but # not in Python. In Python only \r (Carriage Return, 0xD) and \n (Line Feed, # 0xA) are allowed to split lines. diff --git a/libcst/_parser/production_decorator.py b/libcst/_parser/production_decorator.py index c982bc8d9..ffa0d0382 100644 --- a/libcst/_parser/production_decorator.py +++ b/libcst/_parser/production_decorator.py @@ -8,7 +8,6 @@ from libcst._parser.types.conversions import NonterminalConversion from libcst._parser.types.production import Production - _NonterminalConversionT = TypeVar( "_NonterminalConversionT", bound=NonterminalConversion ) diff --git a/libcst/_parser/tests/test_whitespace_parser.py b/libcst/_parser/tests/test_whitespace_parser.py index dcbafa7e0..17996b472 100644 --- a/libcst/_parser/tests/test_whitespace_parser.py +++ b/libcst/_parser/tests/test_whitespace_parser.py @@ -17,7 +17,6 @@ ) from libcst.testing.utils import UnitTest, data_provider - _T = TypeVar("_T") diff --git a/libcst/_parser/tests/test_wrapped_tokenize.py b/libcst/_parser/tests/test_wrapped_tokenize.py index 56bf3dbde..e131f6208 100644 --- a/libcst/_parser/tests/test_wrapped_tokenize.py +++ b/libcst/_parser/tests/test_wrapped_tokenize.py @@ -13,7 +13,6 @@ from libcst._parser.wrapped_tokenize import Token, tokenize from libcst.testing.utils import UnitTest, data_provider - _PY38 = parse_version_string("3.8.0") _PY37 = parse_version_string("3.7.0") _PY36 = parse_version_string("3.6.0") diff --git a/libcst/_parser/types/config.py b/libcst/_parser/types/config.py index 7c76e4c71..13778b2ae 100644 --- a/libcst/_parser/types/config.py +++ b/libcst/_parser/types/config.py @@ -16,7 +16,6 @@ from libcst._nodes.whitespace import NEWLINE_RE from libcst._parser.parso.utils import PythonVersionInfo, parse_version_string - _INDENT_RE: Pattern[str] = re.compile(r"[ \t]+") diff --git a/libcst/_parser/types/conversions.py b/libcst/_parser/types/conversions.py index d0193624d..9951e6da5 100644 --- a/libcst/_parser/types/conversions.py +++ b/libcst/_parser/types/conversions.py @@ -8,7 +8,6 @@ from libcst._parser.types.config import ParserConfig from libcst._parser.types.token import Token - # pyre-fixme[33]: Aliased annotation cannot contain `Any`. NonterminalConversion = Callable[[ParserConfig, Sequence[Any]], Any] # pyre-fixme[33]: Aliased annotation cannot contain `Any`. diff --git a/libcst/_parser/types/partials.py b/libcst/_parser/types/partials.py index a53f37780..abd350712 100644 --- a/libcst/_parser/types/partials.py +++ b/libcst/_parser/types/partials.py @@ -29,7 +29,6 @@ from libcst._nodes.whitespace import EmptyLine, SimpleWhitespace, TrailingWhitespace from libcst._parser.types.whitespace_state import WhitespaceState - _T = TypeVar("_T") diff --git a/libcst/_parser/whitespace_parser.py b/libcst/_parser/whitespace_parser.py index b9df6c7e1..27892a271 100644 --- a/libcst/_parser/whitespace_parser.py +++ b/libcst/_parser/whitespace_parser.py @@ -31,7 +31,6 @@ from libcst._parser.types.config import BaseWhitespaceParserConfig from libcst._parser.types.whitespace_state import WhitespaceState as State - # BEGIN PARSER ENTRYPOINTS diff --git a/libcst/_parser/wrapped_tokenize.py b/libcst/_parser/wrapped_tokenize.py index 6104757d0..d77ed68c7 100644 --- a/libcst/_parser/wrapped_tokenize.py +++ b/libcst/_parser/wrapped_tokenize.py @@ -35,7 +35,6 @@ from libcst._parser.types.token import Token from libcst._parser.types.whitespace_state import WhitespaceState - _ERRORTOKEN: TokenType = PythonTokenTypes.ERRORTOKEN _ERROR_DEDENT: TokenType = PythonTokenTypes.ERROR_DEDENT diff --git a/libcst/_position.py b/libcst/_position.py index 82411402b..be99d4d39 100644 --- a/libcst/_position.py +++ b/libcst/_position.py @@ -17,7 +17,6 @@ from libcst._add_slots import add_slots - _CodePositionT = Union[Tuple[int, int], "CodePosition"] diff --git a/libcst/_type_enforce.py b/libcst/_type_enforce.py index 12cb423f8..92f158d35 100644 --- a/libcst/_type_enforce.py +++ b/libcst/_type_enforce.py @@ -8,7 +8,6 @@ from typing_extensions import Literal from typing_inspect import get_args, get_origin, is_classvar, is_typevar, is_union_type - try: # py37+ from typing import ForwardRef except ImportError: # py36 diff --git a/libcst/_typed_visitor.py b/libcst/_typed_visitor.py index 0246c7187..f536ca3a3 100644 --- a/libcst/_typed_visitor.py +++ b/libcst/_typed_visitor.py @@ -5,7 +5,7 @@ # This file was generated by libcst.codegen.gen_matcher_classes -from typing import TYPE_CHECKING, Optional, Union +from typing import Optional, Union, TYPE_CHECKING from libcst._flatten_sentinel import FlattenSentinel from libcst._maybe_sentinel import MaybeSentinel @@ -28,10 +28,10 @@ BinaryOperation, BooleanOperation, Call, - Comparison, - ComparisonTarget, CompFor, CompIf, + Comparison, + ComparisonTarget, ConcatenatedString, Dict, DictComp, @@ -57,9 +57,9 @@ Name, NamedExpr, Param, - Parameters, ParamSlash, ParamStar, + Parameters, RightCurlyBrace, RightParen, RightSquareBracket, diff --git a/libcst/_typed_visitor_base.py b/libcst/_typed_visitor_base.py index 8525b050a..41b115c18 100644 --- a/libcst/_typed_visitor_base.py +++ b/libcst/_typed_visitor_base.py @@ -5,7 +5,6 @@ from typing import TYPE_CHECKING, Any, Callable, TypeVar, cast - if TYPE_CHECKING: from libcst._typed_visitor import CSTTypedBaseFunctions # noqa: F401 diff --git a/libcst/_types.py b/libcst/_types.py index b6b2ea9cb..8c5c380fe 100644 --- a/libcst/_types.py +++ b/libcst/_types.py @@ -6,7 +6,6 @@ from typing import TYPE_CHECKING, TypeVar - if TYPE_CHECKING: from libcst._nodes.base import CSTNode # noqa: F401 diff --git a/libcst/_visitors.py b/libcst/_visitors.py index 8da37dbf3..6bb8557ba 100644 --- a/libcst/_visitors.py +++ b/libcst/_visitors.py @@ -11,7 +11,6 @@ from libcst._typed_visitor import CSTTypedTransformerFunctions, CSTTypedVisitorFunctions from libcst._types import CSTNodeT - if TYPE_CHECKING: # Circular dependency for typing reasons only from libcst._nodes.base import CSTNode # noqa: F401 diff --git a/libcst/codegen/gen_matcher_classes.py b/libcst/codegen/gen_matcher_classes.py index 7bb7120d3..b34755707 100644 --- a/libcst/codegen/gen_matcher_classes.py +++ b/libcst/codegen/gen_matcher_classes.py @@ -11,7 +11,6 @@ from libcst import ensure_type, parse_expression from libcst.codegen.gather import all_libcst_nodes, typeclasses - CST_DIR: Set[str] = set(dir(cst)) CLASS_RE = r"" OPTIONAL_RE = r"typing\.Union\[([^,]*?), NoneType]" diff --git a/libcst/codegen/gen_type_mapping.py b/libcst/codegen/gen_type_mapping.py index 2f6b2a9d8..0f229e064 100644 --- a/libcst/codegen/gen_type_mapping.py +++ b/libcst/codegen/gen_type_mapping.py @@ -7,7 +7,6 @@ from libcst.codegen.gather import imports, nodebases, nodeuses - generated_code: List[str] = [] generated_code.append("# Copyright (c) Facebook, Inc. and its affiliates.") generated_code.append("#") diff --git a/libcst/codegen/gen_visitor_functions.py b/libcst/codegen/gen_visitor_functions.py index 0666691b0..07bcf95a9 100644 --- a/libcst/codegen/gen_visitor_functions.py +++ b/libcst/codegen/gen_visitor_functions.py @@ -8,7 +8,6 @@ from libcst.codegen.gather import imports, nodebases, nodeuses - generated_code: List[str] = [] generated_code.append("# Copyright (c) Facebook, Inc. and its affiliates.") generated_code.append("#") diff --git a/libcst/codegen/generate.py b/libcst/codegen/generate.py index 60a952f2a..6779c17b2 100644 --- a/libcst/codegen/generate.py +++ b/libcst/codegen/generate.py @@ -26,8 +26,7 @@ def format_file(fname: str) -> None: with open(os.devnull, "w") as devnull: - subprocess.check_call(["isort", "-q", fname], stdout=devnull, stderr=devnull) - subprocess.check_call(["black", fname], stdout=devnull, stderr=devnull) + subprocess.check_call(["ufmt", "format", fname], stdout=devnull, stderr=devnull) def clean_generated_code(code: str) -> str: diff --git a/libcst/codemod/__init__.py b/libcst/codemod/__init__.py index b2b2feabe..8aec421af 100644 --- a/libcst/codemod/__init__.py +++ b/libcst/codemod/__init__.py @@ -30,7 +30,6 @@ from libcst.codemod._testing import CodemodTest from libcst.codemod._visitor import ContextAwareTransformer, ContextAwareVisitor - __all__ = [ "Codemod", "CodemodContext", diff --git a/libcst/codemod/_cli.py b/libcst/codemod/_cli.py index e4b7ec453..1dff878f9 100644 --- a/libcst/codemod/_cli.py +++ b/libcst/codemod/_cli.py @@ -34,7 +34,6 @@ ) from libcst.metadata import FullRepoManager - _DEFAULT_GENERATED_CODE_MARKER: str = f"@gen{''}erated" diff --git a/libcst/codemod/_command.py b/libcst/codemod/_command.py index 1a11e91eb..0196eb275 100644 --- a/libcst/codemod/_command.py +++ b/libcst/codemod/_command.py @@ -15,7 +15,6 @@ from libcst.codemod.visitors._add_imports import AddImportsVisitor from libcst.codemod.visitors._remove_imports import RemoveImportsVisitor - _Codemod = TypeVar("_Codemod", bound=Codemod) diff --git a/libcst/codemod/_dummy_pool.py b/libcst/codemod/_dummy_pool.py index 922037dd8..f80e06de6 100644 --- a/libcst/codemod/_dummy_pool.py +++ b/libcst/codemod/_dummy_pool.py @@ -6,7 +6,6 @@ from types import TracebackType from typing import Callable, Generator, Iterable, Optional, Type, TypeVar - RetT = TypeVar("RetT") ArgT = TypeVar("ArgT") diff --git a/libcst/codemod/_runner.py b/libcst/codemod/_runner.py index a4b68dd49..1748bd9e7 100644 --- a/libcst/codemod/_runner.py +++ b/libcst/codemod/_runner.py @@ -16,7 +16,6 @@ from libcst import PartialParserConfig, parse_module from libcst.codemod._codemod import Codemod - # All datastructures defined in this class are pickleable so that they can be used # as a return value with the multiprocessing module. diff --git a/libcst/codemod/commands/convert_percent_format_to_fstring.py b/libcst/codemod/commands/convert_percent_format_to_fstring.py index 350327191..2190f8083 100644 --- a/libcst/codemod/commands/convert_percent_format_to_fstring.py +++ b/libcst/codemod/commands/convert_percent_format_to_fstring.py @@ -10,7 +10,6 @@ import libcst.matchers as m from libcst.codemod import VisitorBasedCodemodCommand - USE_FSTRING_SIMPLE_EXPRESSION_MAX_LENGTH = 30 diff --git a/libcst/codemod/commands/remove_unused_imports.py b/libcst/codemod/commands/remove_unused_imports.py index 741f9a46c..b11e44c07 100644 --- a/libcst/codemod/commands/remove_unused_imports.py +++ b/libcst/codemod/commands/remove_unused_imports.py @@ -12,7 +12,6 @@ from libcst.helpers import get_absolute_module_for_import from libcst.metadata import PositionProvider, ProviderT - DEFAULT_SUPPRESS_COMMENT_REGEX = ( r".*\W(noqa|lint-ignore: ?unused-import|lint-ignore: ?F401)(\W.*)?$" ) diff --git a/libcst/codemod/visitors/__init__.py b/libcst/codemod/visitors/__init__.py index bcc570bed..12f36f652 100644 --- a/libcst/codemod/visitors/__init__.py +++ b/libcst/codemod/visitors/__init__.py @@ -14,7 +14,6 @@ from libcst.codemod.visitors._gather_unused_imports import GatherUnusedImportsVisitor from libcst.codemod.visitors._remove_imports import RemoveImportsVisitor - __all__ = [ "AddImportsVisitor", "ApplyTypeAnnotationsVisitor", diff --git a/libcst/codemod/visitors/_gather_string_annotation_names.py b/libcst/codemod/visitors/_gather_string_annotation_names.py index c3d624459..244646f9f 100644 --- a/libcst/codemod/visitors/_gather_string_annotation_names.py +++ b/libcst/codemod/visitors/_gather_string_annotation_names.py @@ -11,7 +11,6 @@ from libcst.codemod._visitor import ContextAwareVisitor from libcst.metadata import MetadataWrapper, QualifiedNameProvider - FUNCS_CONSIDERED_AS_STRING_ANNOTATIONS = {"typing.TypeVar"} diff --git a/libcst/codemod/visitors/_gather_unused_imports.py b/libcst/codemod/visitors/_gather_unused_imports.py index 828603253..89f378447 100644 --- a/libcst/codemod/visitors/_gather_unused_imports.py +++ b/libcst/codemod/visitors/_gather_unused_imports.py @@ -17,7 +17,6 @@ from libcst.metadata import ProviderT, ScopeProvider from libcst.metadata.scope_provider import _gen_dotted_names - MODULES_IGNORED_BY_DEFAULT = {"__future__"} diff --git a/libcst/helpers/__init__.py b/libcst/helpers/__init__.py index 77c4389c2..4621c58fb 100644 --- a/libcst/helpers/__init__.py +++ b/libcst/helpers/__init__.py @@ -20,7 +20,6 @@ ) from libcst.helpers.module import insert_header_comments - __all__ = [ "get_absolute_module_for_import", "get_absolute_module_for_import_or_raise", diff --git a/libcst/helpers/_template.py b/libcst/helpers/_template.py index b1be6e5c1..d1f022527 100644 --- a/libcst/helpers/_template.py +++ b/libcst/helpers/_template.py @@ -9,7 +9,6 @@ import libcst as cst from libcst.helpers.common import ensure_type - TEMPLATE_PREFIX: str = "__LIBCST_MANGLED_NAME_" TEMPLATE_SUFFIX: str = "_EMAN_DELGNAM_TSCBIL__" diff --git a/libcst/matchers/__init__.py b/libcst/matchers/__init__.py index 8b7ba63f2..907c6ff34 100644 --- a/libcst/matchers/__init__.py +++ b/libcst/matchers/__init__.py @@ -11,25 +11,25 @@ from typing_extensions import Literal import libcst as cst -from libcst.matchers._decorators import call_if_inside, call_if_not_inside, leave, visit +from libcst.matchers._decorators import call_if_inside, call_if_not_inside, visit, leave from libcst.matchers._matcher_base import ( AbstractBaseMatcherNodeMeta, - AllOf, - AtLeastN, - AtMostN, BaseMatcherNode, - DoesNotMatch, - DoNotCare, DoNotCareSentinel, + DoNotCare, + TypeOf, + OneOf, + AllOf, + DoesNotMatch, MatchIfTrue, + MatchRegex, MatchMetadata, MatchMetadataIfTrue, - MatchRegex, - OneOf, - SaveMatchedNode, - TypeOf, ZeroOrMore, + AtLeastN, ZeroOrOne, + AtMostN, + SaveMatchedNode, extract, extractall, findall, diff --git a/libcst/matchers/_decorators.py b/libcst/matchers/_decorators.py index 7dd2e7414..b6b236ccc 100644 --- a/libcst/matchers/_decorators.py +++ b/libcst/matchers/_decorators.py @@ -7,7 +7,6 @@ from libcst.matchers._matcher_base import BaseMatcherNode - _CSTVisitFuncT = TypeVar("_CSTVisitFuncT") diff --git a/libcst/matchers/_return_types.py b/libcst/matchers/_return_types.py index d8a22986a..0a9152fe5 100644 --- a/libcst/matchers/_return_types.py +++ b/libcst/matchers/_return_types.py @@ -23,10 +23,10 @@ BinaryOperation, BooleanOperation, Call, - Comparison, - ComparisonTarget, CompFor, CompIf, + Comparison, + ComparisonTarget, ConcatenatedString, Dict, DictComp, @@ -52,9 +52,9 @@ Name, NamedExpr, Param, - Parameters, ParamSlash, ParamStar, + Parameters, RightCurlyBrace, RightParen, RightSquareBracket, diff --git a/libcst/matchers/_visitors.py b/libcst/matchers/_visitors.py index be50edfd3..0c3b65a4b 100644 --- a/libcst/matchers/_visitors.py +++ b/libcst/matchers/_visitors.py @@ -45,7 +45,6 @@ ) from libcst.matchers._return_types import TYPED_FUNCTION_RETURN_MAPPING - CONCRETE_METHODS: Set[str] = { *{f"visit_{cls.__name__}" for cls in TYPED_FUNCTION_RETURN_MAPPING}, *{f"leave_{cls.__name__}" for cls in TYPED_FUNCTION_RETURN_MAPPING}, diff --git a/libcst/metadata/__init__.py b/libcst/metadata/__init__.py index bada687e4..55a48cb5d 100644 --- a/libcst/metadata/__init__.py +++ b/libcst/metadata/__init__.py @@ -50,7 +50,6 @@ from libcst.metadata.type_inference_provider import TypeInferenceProvider from libcst.metadata.wrapper import MetadataWrapper - __all__ = [ "CodePosition", "CodeRange", diff --git a/libcst/metadata/base_provider.py b/libcst/metadata/base_provider.py index b2910f5c1..24949b533 100644 --- a/libcst/metadata/base_provider.py +++ b/libcst/metadata/base_provider.py @@ -26,7 +26,6 @@ ) from libcst._visitors import CSTVisitor - if TYPE_CHECKING: from libcst._nodes.base import CSTNode from libcst._nodes.module import Module, _ModuleSelfT as _ModuleT diff --git a/libcst/metadata/full_repo_manager.py b/libcst/metadata/full_repo_manager.py index 0baf5b586..cec74e7f0 100644 --- a/libcst/metadata/full_repo_manager.py +++ b/libcst/metadata/full_repo_manager.py @@ -10,7 +10,6 @@ import libcst as cst from libcst.metadata.wrapper import MetadataWrapper - if TYPE_CHECKING: from libcst.metadata.base_provider import ProviderT # noqa: F401 diff --git a/libcst/metadata/position_provider.py b/libcst/metadata/position_provider.py index 7bd1e7134..004487b3f 100644 --- a/libcst/metadata/position_provider.py +++ b/libcst/metadata/position_provider.py @@ -16,7 +16,6 @@ from libcst._position import CodePosition, CodeRange from libcst.metadata.base_provider import BaseMetadataProvider - NEWLINE_RE: Pattern[str] = re.compile(r"\r\n?|\n") diff --git a/libcst/metadata/scope_provider.py b/libcst/metadata/scope_provider.py index 3b5d380e9..821855c9b 100644 --- a/libcst/metadata/scope_provider.py +++ b/libcst/metadata/scope_provider.py @@ -34,7 +34,6 @@ ExpressionContextProvider, ) - # Comprehensions are handled separately in _visit_comp_alike due to # the complexity of the semantics _ASSIGNMENT_LIKE_NODES = ( diff --git a/libcst/metadata/tests/test_full_repo_manager.py b/libcst/metadata/tests/test_full_repo_manager.py index ff7ebfd02..c7a458d19 100644 --- a/libcst/metadata/tests/test_full_repo_manager.py +++ b/libcst/metadata/tests/test_full_repo_manager.py @@ -12,7 +12,6 @@ from libcst.metadata.type_inference_provider import TypeInferenceProvider from libcst.testing.utils import UnitTest - REPO_ROOT_DIR: str = str(Path(__file__).parent.parent.parent.resolve()) diff --git a/libcst/metadata/wrapper.py b/libcst/metadata/wrapper.py index 6c31b17f7..9ff9b4a06 100644 --- a/libcst/metadata/wrapper.py +++ b/libcst/metadata/wrapper.py @@ -25,7 +25,6 @@ from libcst._exceptions import MetadataException from libcst.metadata.base_provider import BatchableMetadataProvider - if TYPE_CHECKING: from libcst._nodes.base import CSTNode # noqa: F401 from libcst._nodes.module import Module # noqa: F401 diff --git a/libcst/testing/utils.py b/libcst/testing/utils.py index cba70ed1d..5a1e2023c 100644 --- a/libcst/testing/utils.py +++ b/libcst/testing/utils.py @@ -22,7 +22,6 @@ ) from unittest import TestCase - DATA_PROVIDER_DATA_ATTR_NAME = "__data_provider_data" DATA_PROVIDER_DESCRIPTION_PREFIX = "_data_provider_" PROVIDER_TEST_LIMIT_ATTR_NAME = "__provider_test_limit" diff --git a/libcst/tests/test_fuzz.py b/libcst/tests/test_fuzz.py index 590449c7b..66b322761 100644 --- a/libcst/tests/test_fuzz.py +++ b/libcst/tests/test_fuzz.py @@ -20,7 +20,6 @@ import libcst - # If in doubt, you should use these "unit test" settings. They tune the timeouts # and example-reproduction behaviour for these tests' unusually large inputs. hypothesis.settings.register_profile( diff --git a/libcst/tests/test_pyre_integration.py b/libcst/tests/test_pyre_integration.py index 6192dcff1..98675787b 100644 --- a/libcst/tests/test_pyre_integration.py +++ b/libcst/tests/test_pyre_integration.py @@ -17,7 +17,6 @@ ) from libcst.testing.utils import UnitTest, data_provider - TEST_SUITE_PATH: Path = Path(__file__).parent / "pyre" diff --git a/libcst/tests/test_type_enforce.py b/libcst/tests/test_type_enforce.py index edc283e5b..aa4171563 100644 --- a/libcst/tests/test_type_enforce.py +++ b/libcst/tests/test_type_enforce.py @@ -28,7 +28,6 @@ from libcst._type_enforce import is_value_of_type from libcst.testing.utils import UnitTest, data_provider - if TYPE_CHECKING: from collections import Counter # noqa: F401 diff --git a/libcst/tool.py b/libcst/tool.py index fff190c25..44fd367ad 100644 --- a/libcst/tool.py +++ b/libcst/tool.py @@ -40,7 +40,6 @@ parallel_exec_transform_with_prettyprint, ) - _DEFAULT_INDENT: str = " " diff --git a/pyproject.toml b/pyproject.toml index c55f8d4ed..c9a93f4de 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,2 @@ [tool.black] target-version = ["py36"] - -[tool.isort] -line_length = 88 -multi_line_output = 3 -include_trailing_comma = true -force_grid_wrap = 0 -lines_after_imports = 2 -combine_as_imports = true diff --git a/requirements-dev.txt b/requirements-dev.txt index 0dd8f54d6..5efb06074 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,14 +2,15 @@ black==20.8b1 coverage>=4.5.4 fixit==0.1.1 flake8>=3.7.8 +git+https://github.com/jimmylai/sphinx.git@slots_type_annotation hypothesis>=4.36.0 hypothesmith>=0.0.4 -git+https://github.com/jimmylai/sphinx.git@slots_type_annotation -isort==5.5.3 jupyter>=1.0.0 nbsphinx>=0.4.2 +prompt-toolkit>=2.0.9 pyre-check==0.0.41 +setuptools_scm>=6.0.1 sphinx-rtd-theme>=0.4.3 -prompt-toolkit>=2.0.9 tox>=3.18.1 -setuptools_scm>=6.0.1 +ufmt==1.2 +usort==0.6.3 diff --git a/setup.py b/setup.py index f554140d8..28a404ac0 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,6 @@ import setuptools - # Grab the readme so that our package stays in sync with github. this_directory: str = path.abspath(path.dirname(__file__)) with open(path.join(this_directory, "README.rst"), encoding="utf-8") as f: diff --git a/stubs/tokenize.pyi b/stubs/tokenize.pyi index 284dbf36e..2db19c04f 100644 --- a/stubs/tokenize.pyi +++ b/stubs/tokenize.pyi @@ -66,7 +66,6 @@ from token import ( ) from typing import Callable, Generator, Sequence, Tuple - Hexnumber: str = ... Binnumber: str = ... Octnumber: str = ... diff --git a/tox.ini b/tox.ini index 8be5e9b28..1c2057215 100644 --- a/tox.ini +++ b/tox.ini @@ -20,8 +20,7 @@ commands = [testenv:lint] commands = flake8 {posargs} - isort --check-only {posargs:.} - black --check {posargs:libcst/} + ufmt check {posargs:.} python3 -m fixit.cli.run_rules [testenv:docs] @@ -31,8 +30,7 @@ commands = [testenv:autofix] commands = flake8 {posargs} - isort -q {posargs:.} - black {posargs:libcst/} + ufmt format {posargs:.} python3 -m fixit.cli.apply_fix [testenv:pyre]