From 31ce0a3d0845f18e316f36189f9ba2e303a5429e Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Sun, 23 Jan 2022 14:27:22 +0100 Subject: [PATCH] BUG: Make sure string has at least 2 characters --- flake8_simplify.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flake8_simplify.py b/flake8_simplify.py index f3bcba4..c6487f3 100644 --- a/flake8_simplify.py +++ b/flake8_simplify.py @@ -116,7 +116,7 @@ def __init__(self, orig: ast.Call) -> None: def strip_parenthesis(string: str) -> str: - if string[0] == "(" and string[-1] == ")": + if len(string) >= 2 and string[0] == "(" and string[-1] == ")": return string[1:-1] return string @@ -139,7 +139,7 @@ def use_double_quotes(string: str) -> str: quotes = "'''" if string.startswith(quotes) and string.endswith(quotes): return f'"""{string[len(quotes):-len(quotes)]}"""' - if string[0] == "'" and string[-1] == "'": + if len(string) >= 2 and string[0] == "'" and string[-1] == "'": return f'"{string[1:-1]}"' return string