Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion libcst/_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from libcst._tabs import expand_tabs


_NEWLINE_CHARS: str = "\r\n"


Expand Down
7 changes: 3 additions & 4 deletions libcst/_nodes/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from typing import Callable, Generator, Literal, Optional, Sequence, Union

from libcst import CSTLogicError

from libcst._add_slots import add_slots
from libcst._maybe_sentinel import MaybeSentinel
from libcst._nodes.base import CSTCodegenError, CSTNode, CSTValidationError
Expand Down Expand Up @@ -2741,12 +2740,12 @@ class IfExp(BaseExpression):
If statements are provided by :class:`If` and :class:`Else` nodes.
"""

#: The test to perform.
test: BaseExpression

#: The expression to evaluate when the test is true.
body: BaseExpression

#: The test to perform.
test: BaseExpression

#: The expression to evaluate when the test is false.
orelse: BaseExpression

Expand Down
1 change: 0 additions & 1 deletion libcst/_nodes/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from typing import Literal, Optional, Pattern, Sequence, Union

from libcst import CSTLogicError

from libcst._add_slots import add_slots
from libcst._maybe_sentinel import MaybeSentinel
from libcst._nodes.base import CSTNode, CSTValidationError
Expand Down
6 changes: 2 additions & 4 deletions libcst/_nodes/tests/test_cst_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ def test_repr(self) -> None:
),
)
),
dedent(
"""
dedent("""
SimpleStatementLine(
body=[
Pass(
Expand Down Expand Up @@ -188,8 +187,7 @@ def test_repr(self) -> None:
),
),
)
"""
).strip(),
""").strip(),
)

def test_visit(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions libcst/_nodes/tests/test_ifexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,17 @@ def test_valid(
(
(
lambda: cst.IfExp(
cst.Name("bar"),
cst.Name("foo"),
cst.Name("bar"),
cst.Name("baz"),
lpar=(cst.LeftParen(),),
),
"left paren without right paren",
),
(
lambda: cst.IfExp(
cst.Name("bar"),
cst.Name("foo"),
cst.Name("bar"),
cst.Name("baz"),
rpar=(cst.RightParen(),),
),
Expand Down
1 change: 0 additions & 1 deletion libcst/_nodes/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import libcst as cst
from libcst import parse_module, parse_statement
from libcst._nodes.tests.base import CSTNodeTest

from libcst.metadata import CodeRange, MetadataWrapper, PositionProvider
from libcst.testing.utils import data_provider

Expand Down
14 changes: 7 additions & 7 deletions libcst/_parser/conversions/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
def convert_expression_input(
config: ParserConfig, children: typing.Sequence[typing.Any]
) -> typing.Any:
(child, endmarker) = children
child, endmarker = children
# HACK: UGLY! REMOVE THIS SOON!
# Unwrap WithLeadingWhitespace if it exists. It shouldn't exist by this point, but
# testlist isn't fully implemented, and we currently leak these partial objects.
Expand All @@ -177,7 +177,7 @@ def convert_namedexpr_test(
return test

# Convert all of the operations that have no precedence in a loop
(walrus, value) = assignment
walrus, value = assignment
return WithLeadingWhitespace(
NamedExpr(
target=test.value,
Expand All @@ -201,7 +201,7 @@ def convert_test(
(child,) = children
return child
else:
(body, if_token, test, else_token, orelse) = children
body, if_token, test, else_token, orelse = children
return WithLeadingWhitespace(
IfExp(
body=body.value,
Expand Down Expand Up @@ -718,7 +718,7 @@ def convert_trailer_arglist(
def convert_trailer_subscriptlist(
config: ParserConfig, children: typing.Sequence[typing.Any]
) -> typing.Any:
(lbracket, subscriptlist, rbracket) = children
lbracket, subscriptlist, rbracket = children
return SubscriptPartial(
lbracket=LeftSquareBracket(
whitespace_after=parse_parenthesizable_whitespace(
Expand Down Expand Up @@ -1556,7 +1556,7 @@ def convert_comp_for(
(sync_comp_for,) = children
return sync_comp_for
else:
(async_tok, sync_comp_for) = children
async_tok, sync_comp_for = children
return sync_comp_for.with_changes(
# asynchronous steals the `CompFor`'s `whitespace_before`.
asynchronous=Asynchronous(whitespace_after=sync_comp_for.whitespace_before),
Expand Down Expand Up @@ -1594,7 +1594,7 @@ def convert_yield_expr(
yield_node = Yield(value=None)
else:
# Yielding explicit value
(yield_token, yield_arg) = children
yield_token, yield_arg = children
yield_node = Yield(
value=yield_arg.value,
whitespace_after_yield=parse_parenthesizable_whitespace(
Expand All @@ -1617,7 +1617,7 @@ def convert_yield_arg(
return child
else:
# Its a yield from
(from_token, test) = children
from_token, test = children

return WithLeadingWhitespace(
From(
Expand Down
30 changes: 15 additions & 15 deletions libcst/_parser/conversions/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@

@with_production("stmt_input", "stmt ENDMARKER")
def convert_stmt_input(config: ParserConfig, children: Sequence[Any]) -> Any:
(child, endmarker) = children
child, endmarker = children
return child


Expand Down Expand Up @@ -359,7 +359,7 @@ def convert_pass_stmt(config: ParserConfig, children: Sequence[Any]) -> Any:

@with_production("del_stmt", "'del' exprlist")
def convert_del_stmt(config: ParserConfig, children: Sequence[Any]) -> Any:
(del_name, exprlist) = children
del_name, exprlist = children
return WithLeadingWhitespace(
Del(
target=exprlist.value,
Expand Down Expand Up @@ -393,7 +393,7 @@ def convert_return_stmt(config: ParserConfig, children: Sequence[Any]) -> Any:
keyword.whitespace_before,
)
else:
(keyword, testlist) = children
keyword, testlist = children
return WithLeadingWhitespace(
Return(
value=testlist.value,
Expand Down Expand Up @@ -635,12 +635,12 @@ def convert_raise_stmt(config: ParserConfig, children: Sequence[Any]) -> Any:
exc = None
cause = None
elif len(children) == 2:
(raise_token, test) = children
raise_token, test = children
whitespace_after_raise = parse_simple_whitespace(config, test.whitespace_before)
exc = test.value
cause = None
elif len(children) == 4:
(raise_token, test, from_token, source) = children
raise_token, test, from_token, source = children
whitespace_after_raise = parse_simple_whitespace(config, test.whitespace_before)
exc = test.value
cause = From(
Expand Down Expand Up @@ -685,7 +685,7 @@ def _construct_nameitems(config: ParserConfig, names: Sequence[Any]) -> List[Nam

@with_production("global_stmt", "'global' NAME (',' NAME)*")
def convert_global_stmt(config: ParserConfig, children: Sequence[Any]) -> Any:
(global_token, *names) = children
global_token, *names = children
return WithLeadingWhitespace(
Global(
names=tuple(_construct_nameitems(config, names)),
Expand All @@ -699,7 +699,7 @@ def convert_global_stmt(config: ParserConfig, children: Sequence[Any]) -> Any:

@with_production("nonlocal_stmt", "'nonlocal' NAME (',' NAME)*")
def convert_nonlocal_stmt(config: ParserConfig, children: Sequence[Any]) -> Any:
(nonlocal_token, *names) = children
nonlocal_token, *names = children
return WithLeadingWhitespace(
Nonlocal(
names=tuple(_construct_nameitems(config, names)),
Expand All @@ -714,7 +714,7 @@ def convert_nonlocal_stmt(config: ParserConfig, children: Sequence[Any]) -> Any:
@with_production("assert_stmt", "'assert' test [',' test]")
def convert_assert_stmt(config: ParserConfig, children: Sequence[Any]) -> Any:
if len(children) == 2:
(assert_token, test) = children
assert_token, test = children
assert_node = Assert(
whitespace_after_assert=parse_simple_whitespace(
config, test.whitespace_before
Expand All @@ -723,7 +723,7 @@ def convert_assert_stmt(config: ParserConfig, children: Sequence[Any]) -> Any:
msg=None,
)
else:
(assert_token, test, comma_token, msg) = children
assert_token, test, comma_token, msg = children
assert_node = Assert(
whitespace_after_assert=parse_simple_whitespace(
config, test.whitespace_before
Expand Down Expand Up @@ -814,7 +814,7 @@ def convert_while_stmt(config: ParserConfig, children: Sequence[Any]) -> Any:
while_token, test, while_colon_token, while_suite, *else_block = children

if len(else_block) > 0:
(else_token, else_colon_token, else_suite) = else_block
else_token, else_colon_token, else_suite = else_block
orelse = Else(
leading_lines=parse_empty_lines(config, else_token.whitespace_before),
whitespace_before_colon=parse_simple_whitespace(
Expand Down Expand Up @@ -854,7 +854,7 @@ def convert_for_stmt(config: ParserConfig, children: Sequence[Any]) -> Any:
) = children

if len(else_block) > 0:
(else_token, else_colon_token, else_suite) = else_block
else_token, else_colon_token, else_suite = else_block
orelse = Else(
leading_lines=parse_empty_lines(config, else_token.whitespace_before),
whitespace_before_colon=parse_simple_whitespace(
Expand Down Expand Up @@ -958,14 +958,14 @@ def convert_except_clause(config: ParserConfig, children: Sequence[Any]) -> Any:
test = None
name = None
elif len(children) == 2:
(except_token, test_node) = children
except_token, test_node = children
whitespace_after_except = parse_simple_whitespace(
config, except_token.whitespace_after
)
test = test_node.value
name = None
else:
(except_token, test_node, as_token, name_token) = children
except_token, test_node, as_token, name_token = children
whitespace_after_except = parse_simple_whitespace(
config, except_token.whitespace_after
)
Expand Down Expand Up @@ -993,7 +993,7 @@ def convert_except_clause(config: ParserConfig, children: Sequence[Any]) -> Any:
)
@with_production("with_stmt", "'with' with_item ':' suite", version="<3.1")
def convert_with_stmt(config: ParserConfig, children: Sequence[Any]) -> Any:
(with_token, *items, colon_token, suite) = children
with_token, *items, colon_token, suite = children
item_nodes: List[WithItem] = []

for with_item, maybe_comma in grouper(items, 2):
Expand Down Expand Up @@ -1031,7 +1031,7 @@ def convert_with_stmt(config: ParserConfig, children: Sequence[Any]) -> Any:
@with_production("with_item", "test ['as' expr]")
def convert_with_item(config: ParserConfig, children: Sequence[Any]) -> Any:
if len(children) == 3:
(test, as_token, expr_node) = children
test, as_token, expr_node = children
test_node = test.value
asname = AsName(
whitespace_before_as=parse_simple_whitespace(
Expand Down
38 changes: 12 additions & 26 deletions libcst/_parser/parso/tests/test_tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ def test_simple_with_whitespace(self):

def test_function_whitespace(self):
# Test function definition whitespace identification
fundef = dedent(
"""
fundef = dedent("""
def test_whitespace(*args, **kwargs):
x = 1
if x > 0:
print(True)
"""
)
""")
token_list = _get_token_list(fundef)
for _, value, _, prefix in token_list:
if value == "test_whitespace":
Expand Down Expand Up @@ -122,12 +120,10 @@ def test_tokenize_multiline_III(self):
]

def test_identifier_contains_unicode(self):
fundef = dedent(
"""
fundef = dedent("""
def 我あφ():
pass
"""
)
""")
token_list = _get_token_list(fundef)
unicode_token = token_list[1]
assert unicode_token[0] == NAME
Expand Down Expand Up @@ -237,13 +233,11 @@ def test_error_string(self):
assert endmarker.string == ""

def test_indent_error_recovery(self):
code = dedent(
"""\
code = dedent("""\
str(
from x import a
def
"""
)
""")
lst = _get_token_list(code)
expected = [
# `str(`
Expand All @@ -268,13 +262,11 @@ def test_indent_error_recovery(self):
assert [t.type for t in lst] == expected

def test_error_token_after_dedent(self):
code = dedent(
"""\
code = dedent("""\
class C:
pass
$foo
"""
)
""")
lst = _get_token_list(code)
expected = [
NAME,
Expand All @@ -298,23 +290,17 @@ def test_brackets_no_indentation(self):
There used to be an issue that the parentheses counting would go below
zero. This should not happen.
"""
code = dedent(
"""\
code = dedent("""\
}
{
}
"""
)
""")
lst = _get_token_list(code)
assert [t.type for t in lst] == [OP, NEWLINE, OP, OP, NEWLINE, ENDMARKER]

def test_form_feed(self):
error_token, endmarker = _get_token_list(
dedent(
'''\
\f"""'''
)
)
error_token, endmarker = _get_token_list(dedent('''\
\f"""'''))
assert error_token.prefix == "\f"
assert error_token.string == '"""'
assert endmarker.prefix == ""
Expand Down
Loading