Kaydet (Commit) 5f7e02ad authored tarafından Anthony Sottile's avatar Anthony Sottile Kaydeden (comit) GitHub

Merge pull request #12 from asottile/escaped_newlines

Better handle escaped newlines
...@@ -7,6 +7,7 @@ import collections ...@@ -7,6 +7,7 @@ import collections
import io import io
import sys import sys
from tokenize_rt import ESCAPED_NL
from tokenize_rt import src_to_tokens from tokenize_rt import src_to_tokens
from tokenize_rt import Token from tokenize_rt import Token
from tokenize_rt import tokens_to_src from tokenize_rt import tokens_to_src
...@@ -20,8 +21,8 @@ Literal = collections.namedtuple('Literal', ('node', 'backtrack')) ...@@ -20,8 +21,8 @@ Literal = collections.namedtuple('Literal', ('node', 'backtrack'))
Literal.__new__.__defaults__ = (False,) Literal.__new__.__defaults__ = (False,)
Fix = collections.namedtuple('Fix', ('braces', 'multi_arg', 'initial_indent')) Fix = collections.namedtuple('Fix', ('braces', 'multi_arg', 'initial_indent'))
NEWLINES = frozenset(('NEWLINE', 'NL')) NEWLINES = frozenset((ESCAPED_NL, 'NEWLINE', 'NL'))
NON_CODING_TOKENS = frozenset(('COMMENT', 'NL', UNIMPORTANT_WS)) NON_CODING_TOKENS = frozenset(('COMMENT', ESCAPED_NL, 'NL', UNIMPORTANT_WS))
INDENT_TOKENS = frozenset(('INDENT', UNIMPORTANT_WS)) INDENT_TOKENS = frozenset(('INDENT', UNIMPORTANT_WS))
START_BRACES = frozenset(('(', '{', '[')) START_BRACES = frozenset(('(', '{', '['))
END_BRACES = frozenset((')', '}', ']')) END_BRACES = frozenset((')', '}', ']'))
......
...@@ -17,7 +17,7 @@ setup( ...@@ -17,7 +17,7 @@ setup(
'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy', 'Programming Language :: Python :: Implementation :: PyPy',
], ],
install_requires=['tokenize-rt'], install_requires=['tokenize-rt>=2'],
py_modules=['add_trailing_comma'], py_modules=['add_trailing_comma'],
entry_points={ entry_points={
'console_scripts': ['add-trailing-comma = add_trailing_comma:main'], 'console_scripts': ['add-trailing-comma = add_trailing_comma:main'],
......
...@@ -501,6 +501,11 @@ def test_fix_unhugs_py3_only(src, expected): ...@@ -501,6 +501,11 @@ def test_fix_unhugs_py3_only(src, expected):
' 1, 2, 3, 4,\n' ' 1, 2, 3, 4,\n'
' ],\n' ' ],\n'
']', ']',
# Regression test for #11
'foo.\\\n'
' bar(\n'
' 5,\n'
' )',
), ),
) )
def test_noop_trailing_brace(src): def test_noop_trailing_brace(src):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment