wemake-python-styleguide
wemake-python-styleguide copied to clipboard
Consider using libcst
We can try it: https://github.com/Instagram/LibCST
This might solve a lot of our problems. Like:
- New lines in brackets
- Brackets around operators (like #385 and #214 and #454)
Example:
>>> a = cst.parse_module("""
... print(
... 1,
... 2,
... )
... """
... )
>>> a
Module(
body=[
SimpleStatementLine(
body=[
Expr(
value=Call(
func=Name(
value='print',
lpar=[],
rpar=[],
),
args=[
Arg(
value=Integer(
value='1',
lpar=[],
rpar=[],
),
keyword=None,
equal=MaybeSentinel.DEFAULT,
comma=Comma(
whitespace_before=SimpleWhitespace(
value='',
),
whitespace_after=ParenthesizedWhitespace(
first_line=TrailingWhitespace(
whitespace=SimpleWhitespace(
value='',
),
comment=None,
newline=Newline(
value=None,
),
),
empty_lines=[],
indent=True,
last_line=SimpleWhitespace(
value=' ',
),
),
),
star='',
whitespace_after_star=SimpleWhitespace(
value='',
),
whitespace_after_arg=SimpleWhitespace(
value='',
),
),
Arg(
value=Integer(
value='2',
lpar=[],
rpar=[],
),
keyword=None,
equal=MaybeSentinel.DEFAULT,
comma=Comma(
whitespace_before=SimpleWhitespace(
value='',
),
whitespace_after=ParenthesizedWhitespace(
first_line=TrailingWhitespace(
whitespace=SimpleWhitespace(
value='',
),
comment=None,
newline=Newline(
value=None,
),
),
empty_lines=[],
indent=True,
last_line=SimpleWhitespace(
value='',
),
),
),
star='',
whitespace_after_star=SimpleWhitespace(
value='',
),
whitespace_after_arg=SimpleWhitespace(
value='',
),
),
],
lpar=[],
rpar=[],
whitespace_after_func=SimpleWhitespace(
value='',
),
whitespace_before_args=ParenthesizedWhitespace(
first_line=TrailingWhitespace(
whitespace=SimpleWhitespace(
value='',
),
comment=None,
newline=Newline(
value=None,
),
),
empty_lines=[],
indent=True,
last_line=SimpleWhitespace(
value=' ',
),
),
),
semicolon=MaybeSentinel.DEFAULT,
),
],
leading_lines=[],
trailing_whitespace=TrailingWhitespace(
whitespace=SimpleWhitespace(
value='',
),
comment=None,
newline=Newline(
value=None,
),
),
),
],
header=[
EmptyLine(
indent=True,
whitespace=SimpleWhitespace(
value='',
),
comment=None,
newline=Newline(
value=None,
),
),
],
footer=[],
encoding='utf-8',
default_indent=' ',
default_newline='\n',
has_trailing_newline=True,
)
Implementation: https://github.com/wemake-services/wemake-python-styleguide/pull/1147