Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ast.Str usages with ast.Constant for compatibility with Python 3.14 #157

Merged
merged 1 commit into from
Jan 7, 2025
Merged
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
2 changes: 1 addition & 1 deletion tests/test_asttokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_unicode_offsets(self):

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

Expand Down
4 changes: 2 additions & 2 deletions tests/test_tokenless.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def is_fstring_format_spec(node):
and len(node.values) == 1
and (
(
isinstance(node.values[0], ast.Str)
isinstance(node.values[0], ast.Constant)
and node.values[0].value in ['.2f']
) or (
isinstance(node.values[0], ast.FormattedValue)
Expand Down Expand Up @@ -97,7 +97,7 @@ def check_node(self, atok, node):
atok_text = atok.get_text(node, padded=padded)
if ast_text:
if sys.version_info < (3, 12) and (
ast_text.startswith("f") and isinstance(node, (ast.Str, ast.FormattedValue))
ast_text.startswith("f") and isinstance(node, (ast.Constant, ast.FormattedValue))
or is_fstring_format_spec(node)
or (not fstring_positions_work() and is_fstring_internal_node(node))
):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_replace(self):
source = "foo(bar(1 + 2), 'hello' + ', ' + 'world')"
atok = asttokens.ASTTokens(source, parse=True)
names = [n for n in asttokens.util.walk(atok.tree) if isinstance(n, ast.Name)]
strings = [n for n in asttokens.util.walk(atok.tree) if isinstance(n, ast.Str)]
strings = [n for n in asttokens.util.walk(atok.tree) if isinstance(n, ast.Constant) and isinstance(n.value, str)]
repl1 = [atok.get_text_range(n) + ('TEST',) for n in names]
repl2 = [atok.get_text_range(n) + ('val',) for n in strings]
self.assertEqual(asttokens.util.replace(source, repl1 + repl2),
Expand Down
Loading