Skip to content

Commit

Permalink
The ufmt tool combines usort and black with a consistent wrapper,
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stroxler committed Aug 25, 2021
1 parent 5928f6a commit 389bbcd
Show file tree
Hide file tree
Showing 73 changed files with 5 additions and 85 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions libcst/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -207,7 +206,6 @@
)
from libcst.metadata.wrapper import MetadataWrapper


__all__ = [
"KNOWN_PYTHON_VERSION_STRINGS",
"LIBCST_VERSION",
Expand Down
1 change: 0 additions & 1 deletion libcst/_add_slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import dataclasses
from typing import Any, Mapping, Type, TypeVar


_T = TypeVar("_T")


Expand Down
1 change: 0 additions & 1 deletion libcst/_batched_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion libcst/_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion libcst/_flatten_sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import sys


# PEP 585
if sys.version_info < (3, 9):
from typing import Iterable, Sequence
Expand Down
1 change: 0 additions & 1 deletion libcst/_metadata_dependent.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
cast,
)


if TYPE_CHECKING:
# Circular dependency for typing reasons only
from libcst._nodes.base import CSTNode # noqa: F401
Expand Down
1 change: 0 additions & 1 deletion libcst/_nodes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"] = ()

Expand Down
1 change: 0 additions & 1 deletion libcst/_nodes/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion libcst/_nodes/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion libcst/_nodes/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
)
from libcst._visitors import CSTVisitorT


_INDENT_WHITESPACE_RE: Pattern[str] = re.compile(r"[ \f\t]+", re.UNICODE)


Expand Down
1 change: 0 additions & 1 deletion libcst/_nodes/tests/test_cst_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from libcst._visitors import CSTTransformer
from libcst.testing.utils import UnitTest, data_provider, none_throws


_EMPTY_SIMPLE_WHITESPACE = cst.SimpleWhitespace("")


Expand Down
1 change: 0 additions & 1 deletion libcst/_nodes/whitespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/conversions/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/conversions/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
parse_simple_whitespace,
)


AUGOP_TOKEN_LUT: Dict[str, Type[BaseAugOp]] = {
"+=": AddAssign,
"-=": SubtractAssign,
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/custom_itertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from itertools import zip_longest
from typing import Iterable, Iterator, TypeVar


_T = TypeVar("_T")


Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/detect_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from libcst._parser.python_parser import PythonCSTParser
from libcst._parser.types.config import PartialParserConfig


_DEFAULT_PARTIAL_PARSER_CONFIG: PartialParserConfig = PartialParserConfig()


Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/parso/pgen2/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

from libcst._parser.parso.pgen2.grammar_parser import GrammarParser, NFAState


_TokenTypeT = TypeVar("_TokenTypeT")


Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/parso/python/tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/parso/tests/test_tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/parso/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/production_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from libcst._parser.types.conversions import NonterminalConversion
from libcst._parser.types.production import Production


_NonterminalConversionT = TypeVar(
"_NonterminalConversionT", bound=NonterminalConversion
)
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/tests/test_whitespace_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
)
from libcst.testing.utils import UnitTest, data_provider


_T = TypeVar("_T")


Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/tests/test_wrapped_tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/types/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]+")


Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/types/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/types/partials.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from libcst._nodes.whitespace import EmptyLine, SimpleWhitespace, TrailingWhitespace
from libcst._parser.types.whitespace_state import WhitespaceState


_T = TypeVar("_T")


Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/whitespace_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from libcst._parser.types.config import BaseWhitespaceParserConfig
from libcst._parser.types.whitespace_state import WhitespaceState as State


# BEGIN PARSER ENTRYPOINTS


Expand Down
1 change: 0 additions & 1 deletion libcst/_parser/wrapped_tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion libcst/_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

from libcst._add_slots import add_slots


_CodePositionT = Union[Tuple[int, int], "CodePosition"]


Expand Down
1 change: 0 additions & 1 deletion libcst/_type_enforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion libcst/_typed_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from libcst._removal_sentinel import RemovalSentinel
from libcst._typed_visitor_base import mark_no_op


if TYPE_CHECKING:
from libcst._nodes.expression import ( # noqa: F401
Annotation,
Expand Down
1 change: 0 additions & 1 deletion libcst/_typed_visitor_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from typing import TYPE_CHECKING, Any, Callable, TypeVar, cast


if TYPE_CHECKING:
from libcst._typed_visitor import CSTTypedBaseFunctions # noqa: F401

Expand Down
1 change: 0 additions & 1 deletion libcst/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from typing import TYPE_CHECKING, TypeVar


if TYPE_CHECKING:
from libcst._nodes.base import CSTNode # noqa: F401

Expand Down
1 change: 0 additions & 1 deletion libcst/_visitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion libcst/codegen/gen_matcher_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"<class \'(.*?)\'>"
OPTIONAL_RE = r"typing\.Union\[([^,]*?), NoneType]"
Expand Down
1 change: 0 additions & 1 deletion libcst/codegen/gen_type_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("#")
Expand Down
1 change: 0 additions & 1 deletion libcst/codegen/gen_visitor_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("#")
Expand Down
1 change: 0 additions & 1 deletion libcst/codemod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from libcst.codemod._testing import CodemodTest
from libcst.codemod._visitor import ContextAwareTransformer, ContextAwareVisitor


__all__ = [
"Codemod",
"CodemodContext",
Expand Down
1 change: 0 additions & 1 deletion libcst/codemod/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
)
from libcst.metadata import FullRepoManager


_DEFAULT_GENERATED_CODE_MARKER: str = f"@gen{''}erated"


Expand Down
1 change: 0 additions & 1 deletion libcst/codemod/_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
1 change: 0 additions & 1 deletion libcst/codemod/_dummy_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from types import TracebackType
from typing import Callable, Generator, Iterable, Optional, Type, TypeVar


RetT = TypeVar("RetT")
ArgT = TypeVar("ArgT")

Expand Down
1 change: 0 additions & 1 deletion libcst/codemod/_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import libcst.matchers as m
from libcst.codemod import VisitorBasedCodemodCommand


USE_FSTRING_SIMPLE_EXPRESSION_MAX_LENGTH = 30


Expand Down
1 change: 0 additions & 1 deletion libcst/codemod/commands/remove_unused_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.*)?$"
)
Expand Down
Loading

0 comments on commit 389bbcd

Please sign in to comment.