From bf5fb4132e04ac87e1f72c86e37c62dc6594dc9d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:46:01 -0700 Subject: [PATCH] Bump black from 23.12.1 to 24.8.0 (#1186) * Bump black from 23.12.1 to 24.8.0 Bumps [black](https://github.com/psf/black) from 23.12.1 to 24.8.0. - [Release notes](https://github.com/psf/black/releases) - [Changelog](https://github.com/psf/black/blob/main/CHANGES.md) - [Commits](https://github.com/psf/black/compare/23.12.1...24.8.0) --- updated-dependencies: - dependency-name: black dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] * Update formatting --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Amethyst Reese --- libcst/_nodes/base.py | 3 +- libcst/_nodes/expression.py | 27 +++++++------ libcst/_nodes/op.py | 9 ++--- libcst/_nodes/statement.py | 39 +++++++++---------- libcst/_parser/base_parser.py | 6 +-- libcst/_parser/parso/pgen2/generator.py | 6 +-- libcst/_parser/types/config.py | 6 +-- libcst/_position.py | 6 +-- libcst/_typed_visitor.py | 3 ++ .../convert_namedtuple_to_dataclass.py | 4 +- .../convert_percent_format_to_fstring.py | 8 ++-- libcst/codemod/commands/rename.py | 12 +++--- libcst/metadata/base_provider.py | 3 +- libcst/metadata/scope_provider.py | 28 ++++++------- libcst/metadata/tests/test_scope_provider.py | 16 +++++--- libcst/tool.py | 3 +- pyproject.toml | 2 +- 17 files changed, 90 insertions(+), 91 deletions(-) diff --git a/libcst/_nodes/base.py b/libcst/_nodes/base.py index d9689f8f8..d043cb64d 100644 --- a/libcst/_nodes/base.py +++ b/libcst/_nodes/base.py @@ -292,8 +292,7 @@ def _is_removable(self) -> bool: return False @abstractmethod - def _codegen_impl(self, state: CodegenState) -> None: - ... + def _codegen_impl(self, state: CodegenState) -> None: ... def _codegen(self, state: CodegenState, **kwargs: Any) -> None: state.before_codegen(self) diff --git a/libcst/_nodes/expression.py b/libcst/_nodes/expression.py index 75f7da133..a8f2ac3ec 100644 --- a/libcst/_nodes/expression.py +++ b/libcst/_nodes/expression.py @@ -1647,9 +1647,9 @@ def concat(substrings: Sequence[str]) -> str: #: colon or arrow. annotation: BaseExpression - whitespace_before_indicator: Union[ - BaseParenthesizableWhitespace, MaybeSentinel - ] = MaybeSentinel.DEFAULT + whitespace_before_indicator: Union[BaseParenthesizableWhitespace, MaybeSentinel] = ( + MaybeSentinel.DEFAULT + ) whitespace_after_indicator: BaseParenthesizableWhitespace = SimpleWhitespace.field( " " ) @@ -2101,9 +2101,9 @@ class Lambda(BaseExpression): rpar: Sequence[RightParen] = () #: Whitespace after the lambda keyword, but before any argument or the colon. - whitespace_after_lambda: Union[ - BaseParenthesizableWhitespace, MaybeSentinel - ] = MaybeSentinel.DEFAULT + whitespace_after_lambda: Union[BaseParenthesizableWhitespace, MaybeSentinel] = ( + MaybeSentinel.DEFAULT + ) def _safe_to_use_with_word_operator(self, position: ExpressionPosition) -> bool: if position == ExpressionPosition.LEFT: @@ -2601,9 +2601,9 @@ class From(CSTNode): item: BaseExpression #: The whitespace at the very start of this node. - whitespace_before_from: Union[ - BaseParenthesizableWhitespace, MaybeSentinel - ] = MaybeSentinel.DEFAULT + whitespace_before_from: Union[BaseParenthesizableWhitespace, MaybeSentinel] = ( + MaybeSentinel.DEFAULT + ) #: The whitespace after the ``from`` keyword, but before the ``item``. whitespace_after_from: BaseParenthesizableWhitespace = SimpleWhitespace.field(" ") @@ -2662,9 +2662,9 @@ class Yield(BaseExpression): rpar: Sequence[RightParen] = () #: Whitespace after the ``yield`` keyword, but before the ``value``. - whitespace_after_yield: Union[ - BaseParenthesizableWhitespace, MaybeSentinel - ] = MaybeSentinel.DEFAULT + whitespace_after_yield: Union[BaseParenthesizableWhitespace, MaybeSentinel] = ( + MaybeSentinel.DEFAULT + ) def _validate(self) -> None: # Paren rules and such @@ -2748,8 +2748,7 @@ def _codegen_impl( state: CodegenState, default_comma: bool = False, default_comma_whitespace: bool = False, # False for a single-item collection - ) -> None: - ... + ) -> None: ... class BaseElement(_BaseElementImpl, ABC): diff --git a/libcst/_nodes/op.py b/libcst/_nodes/op.py index e19d24d34..1765f5366 100644 --- a/libcst/_nodes/op.py +++ b/libcst/_nodes/op.py @@ -43,8 +43,7 @@ def _codegen_impl(self, state: CodegenState) -> None: self.whitespace_after._codegen(state) @abstractmethod - def _get_token(self) -> str: - ... + def _get_token(self) -> str: ... class _BaseTwoTokenOp(CSTNode, ABC): @@ -88,8 +87,7 @@ def _codegen_impl(self, state: CodegenState) -> None: self.whitespace_after._codegen(state) @abstractmethod - def _get_tokens(self) -> Tuple[str, str]: - ... + def _get_tokens(self) -> Tuple[str, str]: ... class BaseUnaryOp(CSTNode, ABC): @@ -115,8 +113,7 @@ def _codegen_impl(self, state: CodegenState) -> None: self.whitespace_after._codegen(state) @abstractmethod - def _get_token(self) -> str: - ... + def _get_token(self) -> str: ... class BaseBooleanOp(_BaseOneTokenOp, ABC): diff --git a/libcst/_nodes/statement.py b/libcst/_nodes/statement.py index e02ae03c3..e6d6915fe 100644 --- a/libcst/_nodes/statement.py +++ b/libcst/_nodes/statement.py @@ -113,8 +113,7 @@ class BaseSmallStatement(CSTNode, ABC): @abstractmethod def _codegen_impl( self, state: CodegenState, default_semicolon: bool = False - ) -> None: - ... + ) -> None: ... @add_slots @@ -273,9 +272,9 @@ class Return(BaseSmallStatement): #: Optional whitespace after the ``return`` keyword before the optional #: value expression. - whitespace_after_return: Union[ - SimpleWhitespace, MaybeSentinel - ] = MaybeSentinel.DEFAULT + whitespace_after_return: Union[SimpleWhitespace, MaybeSentinel] = ( + MaybeSentinel.DEFAULT + ) #: Optional semicolon when this is used in a statement line. This semicolon #: owns the whitespace on both sides of it when it is used. @@ -2403,9 +2402,9 @@ class Raise(BaseSmallStatement): cause: Optional[From] = None #: Any whitespace appearing between the ``raise`` keyword and the exception. - whitespace_after_raise: Union[ - SimpleWhitespace, MaybeSentinel - ] = MaybeSentinel.DEFAULT + whitespace_after_raise: Union[SimpleWhitespace, MaybeSentinel] = ( + MaybeSentinel.DEFAULT + ) #: Optional semicolon when this is used in a statement line. This semicolon #: owns the whitespace on both sides of it when it is used. @@ -3423,15 +3422,15 @@ class MatchAs(MatchPattern): #: Whitespace between ``pattern`` and the ``as`` keyword (if ``pattern`` is not #: ``None``) - whitespace_before_as: Union[ - BaseParenthesizableWhitespace, MaybeSentinel - ] = MaybeSentinel.DEFAULT + whitespace_before_as: Union[BaseParenthesizableWhitespace, MaybeSentinel] = ( + MaybeSentinel.DEFAULT + ) #: Whitespace between the ``as`` keyword and ``name`` (if ``pattern`` is not #: ``None``) - whitespace_after_as: Union[ - BaseParenthesizableWhitespace, MaybeSentinel - ] = MaybeSentinel.DEFAULT + whitespace_after_as: Union[BaseParenthesizableWhitespace, MaybeSentinel] = ( + MaybeSentinel.DEFAULT + ) #: Parenthesis at the beginning of the node lpar: Sequence[LeftParen] = () @@ -3774,16 +3773,16 @@ class TypeAlias(BaseSmallStatement): #: Whitespace between the name and the type parameters (if they exist) or the ``=``. #: If not specified, :class:`MaybeSentinel` will be replaced with a single space if #: there are no type parameters, otherwise no spaces. - whitespace_after_name: Union[ - SimpleWhitespace, MaybeSentinel - ] = MaybeSentinel.DEFAULT + whitespace_after_name: Union[SimpleWhitespace, MaybeSentinel] = ( + MaybeSentinel.DEFAULT + ) #: Whitespace between the type parameters and the ``=``. Always empty if there are #: no type parameters. If not specified, :class:`MaybeSentinel` will be replaced #: with a single space if there are type parameters. - whitespace_after_type_parameters: Union[ - SimpleWhitespace, MaybeSentinel - ] = MaybeSentinel.DEFAULT + whitespace_after_type_parameters: Union[SimpleWhitespace, MaybeSentinel] = ( + MaybeSentinel.DEFAULT + ) #: Whitespace between the ``=`` and the value. whitespace_after_equals: SimpleWhitespace = SimpleWhitespace.field(" ") diff --git a/libcst/_parser/base_parser.py b/libcst/_parser/base_parser.py index ef9e15192..6ab97ab82 100644 --- a/libcst/_parser/base_parser.py +++ b/libcst/_parser/base_parser.py @@ -129,11 +129,9 @@ def parse(self) -> _NodeT: def convert_nonterminal( self, nonterminal: str, children: Sequence[_NodeT] - ) -> _NodeT: - ... + ) -> _NodeT: ... - def convert_terminal(self, token: _TokenT) -> _NodeT: - ... + def convert_terminal(self, token: _TokenT) -> _NodeT: ... def _add_token(self, token: _TokenT) -> None: """ diff --git a/libcst/_parser/parso/pgen2/generator.py b/libcst/_parser/parso/pgen2/generator.py index 4e20e89d7..ae889f336 100644 --- a/libcst/_parser/parso/pgen2/generator.py +++ b/libcst/_parser/parso/pgen2/generator.py @@ -72,9 +72,9 @@ class DFAState(Generic[_TokenTypeT]): def __init__(self, from_rule: str, nfa_set: Set[NFAState], final: NFAState) -> None: self.from_rule = from_rule self.nfa_set = nfa_set - self.arcs: Mapping[ - str, DFAState - ] = {} # map from terminals/nonterminals to DFAState + self.arcs: Mapping[str, DFAState] = ( + {} + ) # map from terminals/nonterminals to DFAState # In an intermediary step we set these nonterminal arcs (which has the # same structure as arcs). These don't contain terminals anymore. self.nonterminal_arcs: Mapping[str, DFAState] = {} diff --git a/libcst/_parser/types/config.py b/libcst/_parser/types/config.py index 1fc32371f..289fd8aef 100644 --- a/libcst/_parser/types/config.py +++ b/libcst/_parser/types/config.py @@ -27,9 +27,9 @@ BaseWhitespaceParserConfig = config_mod.BaseWhitespaceParserConfig ParserConfig = config_mod.ParserConfig -parser_config_asdict: Callable[ - [ParserConfig], Mapping[str, Any] -] = config_mod.parser_config_asdict +parser_config_asdict: Callable[[ParserConfig], Mapping[str, Any]] = ( + config_mod.parser_config_asdict +) class AutoConfig(Enum): diff --git a/libcst/_position.py b/libcst/_position.py index d7ba0d072..e81e9ab45 100644 --- a/libcst/_position.py +++ b/libcst/_position.py @@ -40,12 +40,10 @@ class CodeRange: end: CodePosition @overload - def __init__(self, start: CodePosition, end: CodePosition) -> None: - ... + def __init__(self, start: CodePosition, end: CodePosition) -> None: ... @overload - def __init__(self, start: Tuple[int, int], end: Tuple[int, int]) -> None: - ... + def __init__(self, start: Tuple[int, int], end: Tuple[int, int]) -> None: ... def __init__(self, start: _CodePositionT, end: _CodePositionT) -> None: if isinstance(start, tuple) and isinstance(end, tuple): diff --git a/libcst/_typed_visitor.py b/libcst/_typed_visitor.py index 742d9f100..e63223536 100644 --- a/libcst/_typed_visitor.py +++ b/libcst/_typed_visitor.py @@ -207,6 +207,7 @@ class CSTTypedBaseFunctions: + @mark_no_op def visit_Add(self, node: "Add") -> Optional[bool]: pass @@ -5763,6 +5764,7 @@ def leave_Yield_whitespace_after_yield(self, node: "Yield") -> None: class CSTTypedVisitorFunctions(CSTTypedBaseFunctions): + @mark_no_op def leave_Add(self, original_node: "Add") -> None: pass @@ -6441,6 +6443,7 @@ def leave_Yield(self, original_node: "Yield") -> None: class CSTTypedTransformerFunctions(CSTTypedBaseFunctions): + @mark_no_op def leave_Add(self, original_node: "Add", updated_node: "Add") -> "BaseBinaryOp": return updated_node diff --git a/libcst/codemod/commands/convert_namedtuple_to_dataclass.py b/libcst/codemod/commands/convert_namedtuple_to_dataclass.py index 91e78048f..f1de5b0c5 100644 --- a/libcst/codemod/commands/convert_namedtuple_to_dataclass.py +++ b/libcst/codemod/commands/convert_namedtuple_to_dataclass.py @@ -25,7 +25,9 @@ class ConvertNamedTupleToDataclassCommand(VisitorBasedCodemodCommand): NamedTuple-specific attributes and methods. """ - DESCRIPTION: str = "Convert NamedTuple class declarations to Python 3.7 dataclasses using the @dataclass decorator." + DESCRIPTION: str = ( + "Convert NamedTuple class declarations to Python 3.7 dataclasses using the @dataclass decorator." + ) METADATA_DEPENDENCIES: Sequence[ProviderT] = (QualifiedNameProvider,) # The 'NamedTuple' we are interested in diff --git a/libcst/codemod/commands/convert_percent_format_to_fstring.py b/libcst/codemod/commands/convert_percent_format_to_fstring.py index 9908a5b65..501c9621e 100644 --- a/libcst/codemod/commands/convert_percent_format_to_fstring.py +++ b/libcst/codemod/commands/convert_percent_format_to_fstring.py @@ -97,9 +97,11 @@ def leave_BinaryOperation( parts.append(cst.FormattedStringText(value=token)) expressions: List[cst.CSTNode] = list( *itertools.chain( - [elm.value for elm in expr.elements] - if isinstance(expr, cst.Tuple) - else [expr] + ( + [elm.value for elm in expr.elements] + if isinstance(expr, cst.Tuple) + else [expr] + ) for expr in exprs ) ) diff --git a/libcst/codemod/commands/rename.py b/libcst/codemod/commands/rename.py index 4bd0ee3dc..290f1ac19 100644 --- a/libcst/codemod/commands/rename.py +++ b/libcst/codemod/commands/rename.py @@ -144,9 +144,9 @@ def leave_Import( self.bypass_import = True if replacement_module != import_alias_full_name: self.scheduled_removals.add(original_node) - new_name_node: Union[ - cst.Attribute, cst.Name - ] = self.gen_name_or_attr_node(replacement_module) + new_name_node: Union[cst.Attribute, cst.Name] = ( + self.gen_name_or_attr_node(replacement_module) + ) new_names.append(cst.ImportAlias(name=new_name_node)) else: new_names.append(import_alias) @@ -198,9 +198,9 @@ def leave_ImportFrom( self.scheduled_removals.add(original_node) continue - new_import_alias_name: Union[ - cst.Attribute, cst.Name - ] = self.gen_name_or_attr_node(replacement_obj) + new_import_alias_name: Union[cst.Attribute, cst.Name] = ( + self.gen_name_or_attr_node(replacement_obj) + ) # Rename on the spot only if this is the only imported name under the module. if len(names) == 1: updated_node = updated_node.with_changes( diff --git a/libcst/metadata/base_provider.py b/libcst/metadata/base_provider.py index 2e03416f0..811fed62c 100644 --- a/libcst/metadata/base_provider.py +++ b/libcst/metadata/base_provider.py @@ -48,8 +48,7 @@ def __call__( *, timeout: Optional[int] = None, use_pyproject_toml: bool = False, - ) -> Mapping[str, object]: - ... + ) -> Mapping[str, object]: ... # We can't use an ABCMeta here, because of metaclass conflicts diff --git a/libcst/metadata/scope_provider.py b/libcst/metadata/scope_provider.py index 75f37a06e..ac9c4b9dc 100644 --- a/libcst/metadata/scope_provider.py +++ b/libcst/metadata/scope_provider.py @@ -199,8 +199,7 @@ def _index(self) -> int: return -1 @abc.abstractmethod - def get_qualified_names_for(self, full_name: str) -> Set[QualifiedName]: - ... + def get_qualified_names_for(self, full_name: str) -> Set[QualifiedName]: ... class Assignment(BaseAssignment): @@ -225,9 +224,11 @@ def _index(self) -> int: def get_qualified_names_for(self, full_name: str) -> Set[QualifiedName]: return { QualifiedName( - f"{self.scope._name_prefix}.{full_name}" - if self.scope._name_prefix - else full_name, + ( + f"{self.scope._name_prefix}.{full_name}" + if self.scope._name_prefix + else full_name + ), QualifiedNameSource.LOCAL, ) } @@ -306,9 +307,11 @@ def get_qualified_names_for(self, full_name: str) -> Set[QualifiedName]: remaining_name = remaining_name.lstrip(".") results.add( QualifiedName( - f"{real_name}.{remaining_name}" - if remaining_name - else real_name, + ( + f"{real_name}.{remaining_name}" + if remaining_name + else real_name + ), QualifiedNameSource.IMPORT, ) ) @@ -503,19 +506,16 @@ def __getitem__(self, name: str) -> Set[BaseAssignment]: @abc.abstractmethod def _resolve_scope_for_access( self, name: str, from_scope: "Scope" - ) -> Set[BaseAssignment]: - ... + ) -> Set[BaseAssignment]: ... def __hash__(self) -> int: return id(self) @abc.abstractmethod - def record_global_overwrite(self, name: str) -> None: - ... + def record_global_overwrite(self, name: str) -> None: ... @abc.abstractmethod - def record_nonlocal_overwrite(self, name: str) -> None: - ... + def record_nonlocal_overwrite(self, name: str) -> None: ... def get_qualified_names_for( self, node: Union[str, cst.CSTNode] diff --git a/libcst/metadata/tests/test_scope_provider.py b/libcst/metadata/tests/test_scope_provider.py index a2087645c..fd23e9938 100644 --- a/libcst/metadata/tests/test_scope_provider.py +++ b/libcst/metadata/tests/test_scope_provider.py @@ -653,12 +653,16 @@ def inner_f(): for assignment in scope_of_outer_f["var"] }, { - outer_f_body_var.targets[0].target - if isinstance(outer_f_body_var, cst.Assign) - else outer_f_body_var, - inner_f_body_var.targets[0].target - if isinstance(inner_f_body_var, cst.Assign) - else inner_f_body_var, + ( + outer_f_body_var.targets[0].target + if isinstance(outer_f_body_var, cst.Assign) + else outer_f_body_var + ), + ( + inner_f_body_var.targets[0].target + if isinstance(inner_f_body_var, cst.Assign) + else inner_f_body_var + ), }, ) diff --git a/libcst/tool.py b/libcst/tool.py index 3c00ba8d6..ace15ff6a 100644 --- a/libcst/tool.py +++ b/libcst/tool.py @@ -461,8 +461,7 @@ def serialize(self, key: str, value: object) -> str: return f"{comments}{os.linesep}{self._serialize_impl(key, value)}{os.linesep}" @abstractmethod - def _serialize_impl(self, key: str, value: object) -> str: - ... + def _serialize_impl(self, key: str, value: object) -> str: ... class _StrSerializer(_SerializerBase): diff --git a/pyproject.toml b/pyproject.toml index 16123a812..7ff3421a8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ dependencies = ["pyyaml>=5.2"] [project.optional-dependencies] dev = [ - "black==23.12.1", + "black==24.8.0", "coverage[toml]>=4.5.4", "build>=0.10.0", "fixit==2.1.0",