Skip to content

Commit c1780aa

Browse files
committed
exist tokenizer over-escapes
1 parent 333d1db commit c1780aa

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

tap/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ def tokenize_source(obj: object) -> Generator:
184184
"""Returns a generator for the tokens of the object's source code."""
185185
source = inspect.getsource(obj)
186186
token_generator = tokenize.generate_tokens(StringIO(source).readline)
187-
188187
return token_generator
189188

190189

@@ -206,7 +205,7 @@ def source_line_to_tokens(obj: object) -> Dict[int, List[Dict[str, Union[str, in
206205
for token_type, token, (start_line, start_column), (end_line, end_column), line in tokenize_source(obj):
207206
line_to_tokens.setdefault(start_line, []).append({
208207
'token_type': token_type,
209-
'token': token,
208+
'token': bytes(token, encoding='ascii').decode('unicode-escape'),
210209
'start_line': start_line,
211210
'start_column': start_column,
212211
'end_line': end_line,

tests/test_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,19 @@ class TripleQuoteMultiline:
294294
class_variables['hi'] = {'comment': 'Hello there'}
295295
self.assertEqual(get_class_variables(TripleQuoteMultiline), class_variables)
296296

297+
def test_comments_with_quotes(self):
298+
class MultiquoteMultiline:
299+
bar: int = 0
300+
'\'\'biz baz\''
301+
302+
hi: str
303+
"\"Hello there\"\""
304+
305+
class_variables = OrderedDict()
306+
class_variables['bar'] = {'comment': "''biz baz'"}
307+
class_variables['hi'] = {'comment': '"Hello there""'}
308+
self.assertEqual(get_class_variables(MultiquoteMultiline), class_variables)
309+
297310
def test_single_quote_multiline(self):
298311
class SingleQuoteMultiline:
299312
bar: int = 0

0 commit comments

Comments
 (0)