Skip to content

Commit

Permalink
Update formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
amyreese committed Aug 22, 2024
1 parent d65ff11 commit e8cf3f8
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 90 deletions.
3 changes: 1 addition & 2 deletions libcst/_nodes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 13 additions & 14 deletions libcst/_nodes/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
" "
)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(" ")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 3 additions & 6 deletions libcst/_nodes/op.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
39 changes: 19 additions & 20 deletions libcst/_nodes/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ class BaseSmallStatement(CSTNode, ABC):
@abstractmethod
def _codegen_impl(
self, state: CodegenState, default_semicolon: bool = False
) -> None:
...
) -> None: ...


@add_slots
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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] = ()
Expand Down Expand Up @@ -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(" ")
Expand Down
6 changes: 2 additions & 4 deletions libcst/_parser/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
6 changes: 3 additions & 3 deletions libcst/_parser/parso/pgen2/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}
Expand Down
6 changes: 3 additions & 3 deletions libcst/_parser/types/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 2 additions & 4 deletions libcst/_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions libcst/_typed_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@


class CSTTypedBaseFunctions:

@mark_no_op
def visit_Add(self, node: "Add") -> Optional[bool]:
pass
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion libcst/codemod/commands/convert_namedtuple_to_dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions libcst/codemod/commands/convert_percent_format_to_fstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
Expand Down
12 changes: 6 additions & 6 deletions libcst/codemod/commands/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions libcst/metadata/base_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions libcst/metadata/scope_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
)
}
Expand Down Expand Up @@ -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,
)
)
Expand Down Expand Up @@ -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]
Expand Down
Loading

0 comments on commit e8cf3f8

Please sign in to comment.