From ee8d87f79f7d2059a4c55e073f2d74e538f69e6b Mon Sep 17 00:00:00 2001 From: Pavel Bitiukov Date: Tue, 12 Dec 2023 21:37:12 +0000 Subject: [PATCH] Add fix for the error found by hypothesis --- isort/parse.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/isort/parse.py b/isort/parse.py index 7dfd7cef..2c3c41ef 100644 --- a/isort/parse.py +++ b/isort/parse.py @@ -519,7 +519,11 @@ def file_contents(contents: str, config: Config = DEFAULT_CONFIG) -> ParsedConte if comments and attach_comments_to is not None: attach_comments_to.extend(comments) - if "," in import_string.split(just_imports[-1])[-1]: + if ( + just_imports + and just_imports[-1] + and "," in import_string.split(just_imports[-1])[-1] + ): trailing_commas.add(import_from) else: if comments and attach_comments_to is not None: