From b9f6a8df3956e23bacf4ecda000c6effda05868f Mon Sep 17 00:00:00 2001 From: Robsdedude Date: Wed, 15 Jan 2025 14:10:40 +0100 Subject: [PATCH] Fix usage of deprecated APIs --- src/flake8_picky_parentheses/_redundant_parentheses.py | 10 +++++++++- tox.ini | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/flake8_picky_parentheses/_redundant_parentheses.py b/src/flake8_picky_parentheses/_redundant_parentheses.py index c559995..05ac9d2 100644 --- a/src/flake8_picky_parentheses/_redundant_parentheses.py +++ b/src/flake8_picky_parentheses/_redundant_parentheses.py @@ -13,6 +13,12 @@ from ._util import ParensCords +if sys.version_info < (3, 8): + AstStr = ast.Str +else: + AstStr = ast.Constant + + AST_FIX_PREFIXES = { "else": "if True:\n pass\n", "elif": "if True:\n pass\n", @@ -383,7 +389,7 @@ def _get_exceptions_from_ast(cls, sorted_parens_coords, tree, tokens): if ( parents and isinstance(parents[0], (ast.Tuple, ast.List)) - and isinstance(node, ast.Str) + and isinstance(node, AstStr) ): tokens_slice = slice(parens_coord.token_indexes[0] + 1, parens_coord.token_indexes[1]) @@ -391,6 +397,8 @@ def _get_exceptions_from_ast(cls, sorted_parens_coords, tree, tokens): token for token in tokens[tokens_slice] if token.type == tokenize.STRING ] + if not string_tokens: + continue if string_tokens[0].start[0] != string_tokens[-1].start[0]: rewrite_buffer = ProblemRewrite(parens_coord.open_, None) last_exception_node = node diff --git a/tox.ini b/tox.ini index fc72583..f2042d0 100644 --- a/tox.ini +++ b/tox.ini @@ -7,4 +7,4 @@ requires = virtualenv<20.22.0 # install pytest in the virtualenv where commands will be executed deps = pytest commands = - pytest tests + pytest tests -W error