Skip to content

Commit bb1df14

Browse files
authored
Replace ast.Str usages with ast.Constant (#157)
1 parent 0ebecde commit bb1df14

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

tests/test_asttokens.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def test_unicode_offsets(self):
125125

126126
# Verify that ast parser produces offsets as we expect. This is just to inform the
127127
# implementation.
128-
string_node = next(n for n in ast.walk(root) if isinstance(n, ast.Str))
128+
string_node = next(n for n in ast.walk(root) if isinstance(n, ast.Constant))
129129
self.assertEqual(string_node.lineno, 1)
130130
self.assertEqual(string_node.col_offset, 4)
131131

tests/test_tokenless.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def is_fstring_format_spec(node):
4747
and len(node.values) == 1
4848
and (
4949
(
50-
isinstance(node.values[0], ast.Str)
50+
isinstance(node.values[0], ast.Constant)
5151
and node.values[0].value in ['.2f']
5252
) or (
5353
isinstance(node.values[0], ast.FormattedValue)
@@ -97,7 +97,7 @@ def check_node(self, atok, node):
9797
atok_text = atok.get_text(node, padded=padded)
9898
if ast_text:
9999
if sys.version_info < (3, 12) and (
100-
ast_text.startswith("f") and isinstance(node, (ast.Str, ast.FormattedValue))
100+
ast_text.startswith("f") and isinstance(node, (ast.Constant, ast.FormattedValue))
101101
or is_fstring_format_spec(node)
102102
or (not fstring_positions_work() and is_fstring_internal_node(node))
103103
):

tests/test_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_replace(self):
9898
source = "foo(bar(1 + 2), 'hello' + ', ' + 'world')"
9999
atok = asttokens.ASTTokens(source, parse=True)
100100
names = [n for n in asttokens.util.walk(atok.tree) if isinstance(n, ast.Name)]
101-
strings = [n for n in asttokens.util.walk(atok.tree) if isinstance(n, ast.Str)]
101+
strings = [n for n in asttokens.util.walk(atok.tree) if isinstance(n, ast.Constant) and isinstance(n.value, str)]
102102
repl1 = [atok.get_text_range(n) + ('TEST',) for n in names]
103103
repl2 = [atok.get_text_range(n) + ('val',) for n in strings]
104104
self.assertEqual(asttokens.util.replace(source, repl1 + repl2),

0 commit comments

Comments
 (0)