[clang] [libclang/python/tests] Clean up imports (PR #114409)
Jannick Kremer via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 31 07:25:46 PDT 2024
https://github.com/DeinAlptraum created https://github.com/llvm/llvm-project/pull/114409
Sort imports using `isort`.
Remove unused imports
Collect multiple imports from the same module into a single import statement
Unify import style
>From a83338b9f4b306a81b55937e109e3065049fcfb7 Mon Sep 17 00:00:00 2001
From: Jannick Kremer <jannick.kremer at mailbox.org>
Date: Thu, 31 Oct 2024 13:47:12 +0100
Subject: [PATCH] [libclang/python/tests] Clean up imports
---
.../tests/cindex/test_access_specifiers.py | 12 +++-----
.../bindings/python/tests/cindex/test_cdb.py | 8 ++---
.../tests/cindex/test_code_completion.py | 5 ++--
.../python/tests/cindex/test_comment.py | 8 ++---
.../python/tests/cindex/test_cursor.py | 25 ++++++++--------
.../python/tests/cindex/test_cursor_kind.py | 5 ++--
.../python/tests/cindex/test_diagnostics.py | 7 ++---
.../python/tests/cindex/test_enums.py | 16 +++++-----
.../test_exception_specification_kind.py | 11 ++++---
.../bindings/python/tests/cindex/test_file.py | 5 ++--
.../python/tests/cindex/test_index.py | 6 ++--
.../python/tests/cindex/test_linkage.py | 12 +++-----
.../python/tests/cindex/test_location.py | 19 ++++++------
.../python/tests/cindex/test_rewrite.py | 10 ++-----
.../python/tests/cindex/test_source_range.py | 4 +--
.../python/tests/cindex/test_tls_kind.py | 12 +++-----
.../python/tests/cindex/test_token_kind.py | 5 ++--
.../python/tests/cindex/test_tokens.py | 11 ++-----
.../tests/cindex/test_translation_unit.py | 30 +++++++++----------
.../bindings/python/tests/cindex/test_type.py | 12 ++------
clang/bindings/python/tests/cindex/util.py | 3 +-
21 files changed, 92 insertions(+), 134 deletions(-)
diff --git a/clang/bindings/python/tests/cindex/test_access_specifiers.py b/clang/bindings/python/tests/cindex/test_access_specifiers.py
index c1cc18ebe6e589..ca2bbd3cc86117 100644
--- a/clang/bindings/python/tests/cindex/test_access_specifiers.py
+++ b/clang/bindings/python/tests/cindex/test_access_specifiers.py
@@ -1,18 +1,14 @@
import os
-from clang.cindex import Config
+
+from clang.cindex import AccessSpecifier, Config
if "CLANG_LIBRARY_PATH" in os.environ:
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
-from clang.cindex import AccessSpecifier
-from clang.cindex import Cursor
-from clang.cindex import TranslationUnit
-
-from .util import get_cursor
-from .util import get_tu
-
import unittest
+from .util import get_cursor, get_tu
+
class TestAccessSpecifiers(unittest.TestCase):
def test_access_specifiers(self):
diff --git a/clang/bindings/python/tests/cindex/test_cdb.py b/clang/bindings/python/tests/cindex/test_cdb.py
index 299e79a2708988..342a544c86337b 100644
--- a/clang/bindings/python/tests/cindex/test_cdb.py
+++ b/clang/bindings/python/tests/cindex/test_cdb.py
@@ -1,14 +1,10 @@
import os
-from clang.cindex import Config
+
+from clang.cindex import CompilationDatabase, CompilationDatabaseError, Config
if "CLANG_LIBRARY_PATH" in os.environ:
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
-from clang.cindex import CompilationDatabase
-from clang.cindex import CompilationDatabaseError
-from clang.cindex import CompileCommands
-from clang.cindex import CompileCommand
-import os
import gc
import unittest
import sys
diff --git a/clang/bindings/python/tests/cindex/test_code_completion.py b/clang/bindings/python/tests/cindex/test_code_completion.py
index 921a8f1f0aac87..c7a86aa82a8ebc 100644
--- a/clang/bindings/python/tests/cindex/test_code_completion.py
+++ b/clang/bindings/python/tests/cindex/test_code_completion.py
@@ -1,11 +1,10 @@
import os
-from clang.cindex import Config
+
+from clang.cindex import Config, TranslationUnit
if "CLANG_LIBRARY_PATH" in os.environ:
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
-from clang.cindex import TranslationUnit
-
import unittest
from pathlib import Path
diff --git a/clang/bindings/python/tests/cindex/test_comment.py b/clang/bindings/python/tests/cindex/test_comment.py
index 265c6d3d73de04..1ecbb42c18ffca 100644
--- a/clang/bindings/python/tests/cindex/test_comment.py
+++ b/clang/bindings/python/tests/cindex/test_comment.py
@@ -1,14 +1,14 @@
import os
-from clang.cindex import Config
+
+from clang.cindex import Config, TranslationUnit
if "CLANG_LIBRARY_PATH" in os.environ:
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
-from clang.cindex import TranslationUnit
-from tests.cindex.util import get_cursor
-
import unittest
+from .util import get_cursor
+
class TestComment(unittest.TestCase):
def test_comment(self):
diff --git a/clang/bindings/python/tests/cindex/test_cursor.py b/clang/bindings/python/tests/cindex/test_cursor.py
index 81c7f1c74966f1..4d989a7421e790 100644
--- a/clang/bindings/python/tests/cindex/test_cursor.py
+++ b/clang/bindings/python/tests/cindex/test_cursor.py
@@ -1,24 +1,23 @@
import os
-from clang.cindex import Config
+
+from clang.cindex import (
+ AvailabilityKind,
+ BinaryOperator,
+ Config,
+ CursorKind,
+ StorageClass,
+ TemplateArgumentKind,
+ TranslationUnit,
+ TypeKind,
+)
if "CLANG_LIBRARY_PATH" in os.environ:
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
-import ctypes
import gc
import unittest
-from clang.cindex import AvailabilityKind
-from clang.cindex import CursorKind
-from clang.cindex import TemplateArgumentKind
-from clang.cindex import TranslationUnit
-from clang.cindex import TypeKind
-from clang.cindex import BinaryOperator
-from clang.cindex import StorageClass
-from .util import get_cursor
-from .util import get_cursors
-from .util import get_tu
-
+from .util import get_cursor, get_cursors, get_tu
kInput = """\
struct s0 {
diff --git a/clang/bindings/python/tests/cindex/test_cursor_kind.py b/clang/bindings/python/tests/cindex/test_cursor_kind.py
index 87199dba06ed25..3b693ff45cfd44 100644
--- a/clang/bindings/python/tests/cindex/test_cursor_kind.py
+++ b/clang/bindings/python/tests/cindex/test_cursor_kind.py
@@ -1,11 +1,10 @@
import os
-from clang.cindex import Config
+
+from clang.cindex import Config, CursorKind
if "CLANG_LIBRARY_PATH" in os.environ:
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
-from clang.cindex import CursorKind
-
import unittest
diff --git a/clang/bindings/python/tests/cindex/test_diagnostics.py b/clang/bindings/python/tests/cindex/test_diagnostics.py
index 041083d12c7f16..2ebd3414d692d8 100644
--- a/clang/bindings/python/tests/cindex/test_diagnostics.py
+++ b/clang/bindings/python/tests/cindex/test_diagnostics.py
@@ -1,14 +1,13 @@
import os
-from clang.cindex import Config
+
+from clang.cindex import Config, Diagnostic
if "CLANG_LIBRARY_PATH" in os.environ:
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
-from clang.cindex import *
-from .util import get_tu
-
import unittest
+from .util import get_tu
# FIXME: We need support for invalid translation units to test better.
diff --git a/clang/bindings/python/tests/cindex/test_enums.py b/clang/bindings/python/tests/cindex/test_enums.py
index 63b2292c5d9bdc..9e7f44fcf7867c 100644
--- a/clang/bindings/python/tests/cindex/test_enums.py
+++ b/clang/bindings/python/tests/cindex/test_enums.py
@@ -1,18 +1,18 @@
import unittest
from clang.cindex import (
- TokenKind,
+ AccessSpecifier,
+ AvailabilityKind,
+ BinaryOperator,
CursorKind,
- TemplateArgumentKind,
ExceptionSpecificationKind,
- AvailabilityKind,
- AccessSpecifier,
- TypeKind,
- RefQualifierKind,
LinkageKind,
- TLSKind,
+ RefQualifierKind,
StorageClass,
- BinaryOperator,
+ TemplateArgumentKind,
+ TLSKind,
+ TokenKind,
+ TypeKind,
)
diff --git a/clang/bindings/python/tests/cindex/test_exception_specification_kind.py b/clang/bindings/python/tests/cindex/test_exception_specification_kind.py
index e4742db31adbe2..f7806ffad80124 100644
--- a/clang/bindings/python/tests/cindex/test_exception_specification_kind.py
+++ b/clang/bindings/python/tests/cindex/test_exception_specification_kind.py
@@ -1,18 +1,17 @@
import os
-from clang.cindex import Config
+
+from clang.cindex import Config, CursorKind, ExceptionSpecificationKind
if "CLANG_LIBRARY_PATH" in os.environ:
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
-import clang.cindex
-from clang.cindex import ExceptionSpecificationKind
-from .util import get_tu
-
import unittest
+from .util import get_tu
+
def find_function_declarations(node, declarations=[]):
- if node.kind == clang.cindex.CursorKind.FUNCTION_DECL:
+ if node.kind == CursorKind.FUNCTION_DECL:
declarations.append(node)
for child in node.get_children():
declarations = find_function_declarations(child, declarations)
diff --git a/clang/bindings/python/tests/cindex/test_file.py b/clang/bindings/python/tests/cindex/test_file.py
index 7024b0cdf11d97..14a3084ee2b47a 100644
--- a/clang/bindings/python/tests/cindex/test_file.py
+++ b/clang/bindings/python/tests/cindex/test_file.py
@@ -1,11 +1,10 @@
import os
-from clang.cindex import Config
+
+from clang.cindex import Config, File, Index
if "CLANG_LIBRARY_PATH" in os.environ:
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
-from clang.cindex import Index, File
-
import unittest
diff --git a/clang/bindings/python/tests/cindex/test_index.py b/clang/bindings/python/tests/cindex/test_index.py
index 72146f5f5b08b5..756f4bd9c7dfb5 100644
--- a/clang/bindings/python/tests/cindex/test_index.py
+++ b/clang/bindings/python/tests/cindex/test_index.py
@@ -1,14 +1,12 @@
import os
-from clang.cindex import Config
+
+from clang.cindex import Config, Index, TranslationUnit
if "CLANG_LIBRARY_PATH" in os.environ:
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
-from clang.cindex import *
-import os
import unittest
-
kInputsDir = os.path.join(os.path.dirname(__file__), "INPUTS")
diff --git a/clang/bindings/python/tests/cindex/test_linkage.py b/clang/bindings/python/tests/cindex/test_linkage.py
index 4a8838276fae57..93bf43a0420476 100644
--- a/clang/bindings/python/tests/cindex/test_linkage.py
+++ b/clang/bindings/python/tests/cindex/test_linkage.py
@@ -1,18 +1,14 @@
import os
-from clang.cindex import Config
+
+from clang.cindex import Config, LinkageKind
if "CLANG_LIBRARY_PATH" in os.environ:
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
-from clang.cindex import LinkageKind
-from clang.cindex import Cursor
-from clang.cindex import TranslationUnit
-
-from .util import get_cursor
-from .util import get_tu
-
import unittest
+from .util import get_cursor, get_tu
+
class TestLinkage(unittest.TestCase):
def test_linkage(self):
diff --git a/clang/bindings/python/tests/cindex/test_location.py b/clang/bindings/python/tests/cindex/test_location.py
index 27854a312e6721..bbf79126ab1f8d 100644
--- a/clang/bindings/python/tests/cindex/test_location.py
+++ b/clang/bindings/python/tests/cindex/test_location.py
@@ -1,19 +1,20 @@
import os
-from clang.cindex import Config
+
+from clang.cindex import (
+ Config,
+ Cursor,
+ File,
+ SourceLocation,
+ SourceRange,
+ TranslationUnit,
+)
if "CLANG_LIBRARY_PATH" in os.environ:
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
-from clang.cindex import Cursor
-from clang.cindex import File
-from clang.cindex import SourceLocation
-from clang.cindex import SourceRange
-from clang.cindex import TranslationUnit
-from .util import get_cursor
-from .util import get_tu
-
import unittest
+from .util import get_cursor, get_tu
baseInput = "int one;\nint two;\n"
diff --git a/clang/bindings/python/tests/cindex/test_rewrite.py b/clang/bindings/python/tests/cindex/test_rewrite.py
index 42006f57554e28..6f7e5d906172c1 100644
--- a/clang/bindings/python/tests/cindex/test_rewrite.py
+++ b/clang/bindings/python/tests/cindex/test_rewrite.py
@@ -1,13 +1,7 @@
-import unittest
import tempfile
+import unittest
-from clang.cindex import (
- Rewriter,
- TranslationUnit,
- File,
- SourceLocation,
- SourceRange,
-)
+from clang.cindex import File, Rewriter, SourceLocation, SourceRange, TranslationUnit
class TestRewrite(unittest.TestCase):
diff --git a/clang/bindings/python/tests/cindex/test_source_range.py b/clang/bindings/python/tests/cindex/test_source_range.py
index 47d8960fcafb35..81c0a9b05cff82 100644
--- a/clang/bindings/python/tests/cindex/test_source_range.py
+++ b/clang/bindings/python/tests/cindex/test_source_range.py
@@ -1,11 +1,11 @@
import os
-from clang.cindex import Config
+
+from clang.cindex import Config, SourceLocation, SourceRange, TranslationUnit
if "CLANG_LIBRARY_PATH" in os.environ:
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
import unittest
-from clang.cindex import SourceLocation, SourceRange, TranslationUnit
from .util import get_tu
diff --git a/clang/bindings/python/tests/cindex/test_tls_kind.py b/clang/bindings/python/tests/cindex/test_tls_kind.py
index b8ef74614ab038..f80a46f4d56806 100644
--- a/clang/bindings/python/tests/cindex/test_tls_kind.py
+++ b/clang/bindings/python/tests/cindex/test_tls_kind.py
@@ -1,18 +1,14 @@
import os
-from clang.cindex import Config
+
+from clang.cindex import Config, TLSKind
if "CLANG_LIBRARY_PATH" in os.environ:
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
-from clang.cindex import TLSKind
-from clang.cindex import Cursor
-from clang.cindex import TranslationUnit
-
-from .util import get_cursor
-from .util import get_tu
-
import unittest
+from .util import get_cursor, get_tu
+
class TestTLSKind(unittest.TestCase):
def test_tls_kind(self):
diff --git a/clang/bindings/python/tests/cindex/test_token_kind.py b/clang/bindings/python/tests/cindex/test_token_kind.py
index 747d328a577dc4..594f30a448d84f 100644
--- a/clang/bindings/python/tests/cindex/test_token_kind.py
+++ b/clang/bindings/python/tests/cindex/test_token_kind.py
@@ -1,11 +1,10 @@
import os
-from clang.cindex import Config
+
+from clang.cindex import Config, TokenKind
if "CLANG_LIBRARY_PATH" in os.environ:
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
-from clang.cindex import TokenKind
-
import unittest
diff --git a/clang/bindings/python/tests/cindex/test_tokens.py b/clang/bindings/python/tests/cindex/test_tokens.py
index 2cbf42c4c6cb93..b6c1fc8b836009 100644
--- a/clang/bindings/python/tests/cindex/test_tokens.py
+++ b/clang/bindings/python/tests/cindex/test_tokens.py
@@ -1,19 +1,14 @@
import os
-from clang.cindex import Config
+
+from clang.cindex import Config, CursorKind, SourceLocation, SourceRange, TokenKind
if "CLANG_LIBRARY_PATH" in os.environ:
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
-from clang.cindex import CursorKind
-from clang.cindex import Index
-from clang.cindex import SourceLocation
-from clang.cindex import SourceRange
-from clang.cindex import TokenKind
+import unittest
from .util import get_tu
-import unittest
-
class TestTokens(unittest.TestCase):
def test_token_to_cursor(self):
diff --git a/clang/bindings/python/tests/cindex/test_translation_unit.py b/clang/bindings/python/tests/cindex/test_translation_unit.py
index 6181463b0804f3..56bf3742417554 100644
--- a/clang/bindings/python/tests/cindex/test_translation_unit.py
+++ b/clang/bindings/python/tests/cindex/test_translation_unit.py
@@ -1,28 +1,28 @@
import os
-from clang.cindex import Config
+
+from clang.cindex import (
+ Config,
+ Cursor,
+ CursorKind,
+ File,
+ Index,
+ SourceLocation,
+ SourceRange,
+ TranslationUnit,
+ TranslationUnitLoadError,
+ TranslationUnitSaveError,
+)
if "CLANG_LIBRARY_PATH" in os.environ:
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
-from contextlib import contextmanager
import gc
-import os
import tempfile
import unittest
+from contextlib import contextmanager
from pathlib import Path
-from clang.cindex import CursorKind
-from clang.cindex import Cursor
-from clang.cindex import File
-from clang.cindex import Index
-from clang.cindex import SourceLocation
-from clang.cindex import SourceRange
-from clang.cindex import TranslationUnitSaveError
-from clang.cindex import TranslationUnitLoadError
-from clang.cindex import TranslationUnit
-from .util import get_cursor
-from .util import get_tu
-
+from .util import get_cursor, get_tu
kInputsDir = os.path.join(os.path.dirname(__file__), "INPUTS")
diff --git a/clang/bindings/python/tests/cindex/test_type.py b/clang/bindings/python/tests/cindex/test_type.py
index ef6630c93bb258..ce05fdb1a1ebc0 100644
--- a/clang/bindings/python/tests/cindex/test_type.py
+++ b/clang/bindings/python/tests/cindex/test_type.py
@@ -1,5 +1,6 @@
import os
-from clang.cindex import Config
+
+from clang.cindex import Config, CursorKind, RefQualifierKind, TranslationUnit, TypeKind
if "CLANG_LIBRARY_PATH" in os.environ:
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
@@ -7,14 +8,7 @@
import gc
import unittest
-from clang.cindex import CursorKind
-from clang.cindex import TranslationUnit
-from clang.cindex import TypeKind
-from clang.cindex import RefQualifierKind
-from .util import get_cursor
-from .util import get_cursors
-from .util import get_tu
-
+from .util import get_cursor, get_cursors, get_tu
kInput = """\
diff --git a/clang/bindings/python/tests/cindex/util.py b/clang/bindings/python/tests/cindex/util.py
index e2d150a7b6b431..5e66a9dc82c446 100644
--- a/clang/bindings/python/tests/cindex/util.py
+++ b/clang/bindings/python/tests/cindex/util.py
@@ -1,7 +1,6 @@
# This file provides common utility functions for the test suite.
-from clang.cindex import Cursor
-from clang.cindex import TranslationUnit
+from clang.cindex import Cursor, TranslationUnit
def get_tu(source, lang="c", all_warnings=False, flags=[]):
More information about the cfe-commits
mailing list