From 53c5527bcc4f0a0b6e5e7c7a1ab75325314b5973 Mon Sep 17 00:00:00 2001 From: Mubashir78 Date: Thu, 2 Jul 2026 13:06:40 +0500 Subject: [PATCH] Remove F401 (unused import) ignores and fix all violations - Remove 12 unused imports across the codebase - Remove F401 from all per-file-ignores in pyproject.toml - Drop unused per-file-ignores entries for files where only F401 was ignored Part of #643 --- comtypes/_npsupport.py | 1 - comtypes/automation.py | 2 +- comtypes/client/_constants.py | 1 - comtypes/test/setup.py | 1 - comtypes/test/test_agilent.py | 3 +-- comtypes/test/test_server.py | 4 ++-- comtypes/test/test_urlhistory.py | 1 - comtypes/test/test_variant.py | 2 -- comtypes/tools/typedesc_base.py | 1 - docs/source/conf.py | 1 - pyproject.toml | 21 ++++++++------------- 11 files changed, 12 insertions(+), 26 deletions(-) diff --git a/comtypes/_npsupport.py b/comtypes/_npsupport.py index fa35e1edc..e4c04f66a 100644 --- a/comtypes/_npsupport.py +++ b/comtypes/_npsupport.py @@ -157,7 +157,6 @@ def enable(self): if self.enabled: return # first we have to be able to import numpy - import numpy # if that succeeded we can be enabled self.enabled = True diff --git a/comtypes/automation.py b/comtypes/automation.py index 158cc6a62..d07f65150 100644 --- a/comtypes/automation.py +++ b/comtypes/automation.py @@ -6,7 +6,7 @@ from ctypes import * from ctypes import Array as _CArrayType from ctypes import _Pointer -from ctypes.wintypes import DWORD, LONG, UINT, VARIANT_BOOL, WCHAR, WORD +from ctypes.wintypes import DWORD, LONG, UINT, VARIANT_BOOL, WORD from typing import TYPE_CHECKING, Any, ClassVar, Optional import comtypes diff --git a/comtypes/client/_constants.py b/comtypes/client/_constants.py index 644606cca..535110684 100644 --- a/comtypes/client/_constants.py +++ b/comtypes/client/_constants.py @@ -4,7 +4,6 @@ # ################################################################ import keyword -import sys import comtypes import comtypes.automation diff --git a/comtypes/test/setup.py b/comtypes/test/setup.py index 2c21339ab..cb432c6e3 100644 --- a/comtypes/test/setup.py +++ b/comtypes/test/setup.py @@ -2,6 +2,5 @@ import glob from distutils.core import setup -import py2exe setup(name="test_*", console=glob.glob("test_*.py")) diff --git a/comtypes/test/test_agilent.py b/comtypes/test/test_agilent.py index 793d6dca7..697f2ab6f 100644 --- a/comtypes/test/test_agilent.py +++ b/comtypes/test/test_agilent.py @@ -3,12 +3,11 @@ # connected, the driver is used in simulation mode. import unittest -from ctypes import POINTER, c_double +from ctypes import c_double from comtypes import GUID from comtypes.client import CreateObject from comtypes.safearray import _midlSAFEARRAY -from comtypes.test import ResourceDenied try: GUID.from_progid("Agilent546XX.Agilent546XX") diff --git a/comtypes/test/test_server.py b/comtypes/test/test_server.py index 9bd927fd9..ce7d6e499 100644 --- a/comtypes/test/test_server.py +++ b/comtypes/test/test_server.py @@ -219,7 +219,7 @@ def GetStackTrace(self, this, *args): def test_GetStackTrace(self): p = wrap(self.create()) - from ctypes import POINTER, c_int, pointer + from ctypes import c_int, pointer frames = (c_int * 5)() res = p.GetStackTrace(42, frames, 5) @@ -324,7 +324,7 @@ def OnSomethingElse(self, this, presult): path = tlb.compile() from comtypes.connectionpoints import IConnectionPointContainer from comtypes.gen import TestLib -from comtypes.typeinfo import IProvideClassInfo, IProvideClassInfo2 +from comtypes.typeinfo import IProvideClassInfo2 MyServer._com_interfaces_ = [ TestLib.IMyInterface, diff --git a/comtypes/test/test_urlhistory.py b/comtypes/test/test_urlhistory.py index 083aa32b7..5e1a3d71f 100644 --- a/comtypes/test/test_urlhistory.py +++ b/comtypes/test/test_urlhistory.py @@ -1,6 +1,5 @@ import os import unittest -from copy import copy from ctypes import * from comtypes.client import CreateObject, GetModule diff --git a/comtypes/test/test_variant.py b/comtypes/test/test_variant.py index 599cbf493..c997d845d 100644 --- a/comtypes/test/test_variant.py +++ b/comtypes/test/test_variant.py @@ -42,7 +42,6 @@ VT_UI4, VT_UI8, ) -from comtypes.test.find_memleak import find_memleak from comtypes.typeinfo import LoadRegTypeLib @@ -316,7 +315,6 @@ def check_perf(rep=20000): from ctypes import byref, c_int import comtypes.automation - from comtypes.automation import VARIANT print(comtypes.automation) variable = c_int() diff --git a/comtypes/tools/typedesc_base.py b/comtypes/tools/typedesc_base.py index 5b3110777..cb6bb51c7 100644 --- a/comtypes/tools/typedesc_base.py +++ b/comtypes/tools/typedesc_base.py @@ -2,7 +2,6 @@ from typing import Any, Optional, SupportsInt from typing import Union as _UnionT -import comtypes class Argument: diff --git a/docs/source/conf.py b/docs/source/conf.py index 2374986b3..03077ad0c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -13,7 +13,6 @@ import os import sys -import sphinx_rtd_theme # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the diff --git a/pyproject.toml b/pyproject.toml index c5b38445f..81a284fc6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,36 +64,31 @@ ignore = ["E402"] [tool.ruff.lint.per-file-ignores] # production -"comtypes/_npsupport.py" = ["F401"] "comtypes/_vtbl.py" = ["E722"] -"comtypes/automation.py" = ["F401", "F403", "F405"] +"comtypes/automation.py" = ["F403", "F405"] "comtypes/viewobject.py" = ["F403", "F405"] -"comtypes/client/_constants.py" = ["F401"] "comtypes/server/automation.py" = ["F403", "F405"] -"comtypes/server/connectionpoints.py" = ["F401", "F403", "F405"] +"comtypes/server/connectionpoints.py" = ["F403", "F405"] "comtypes/server/inprocserver.py" = ["E722"] "comtypes/server/register.py" = ["E713"] "comtypes/tools/codegenerator/packing.py" = ["F821", "F841"] "comtypes/tools/typedesc.py" = ["F403", "F405"] -"comtypes/tools/typedesc_base.py" = ["F401"] # gen directory "comtypes/gen/*" = ["E", "F", "I"] # stub "comtypes/hints.pyi" = ["I"] # tests "comtypes/test/TestDispServer.py" = ["E401"] -"comtypes/test/find_memleak.py" = ["E401", "F401", "F403", "F405"] -"comtypes/test/setup.py" = ["F401"] -"comtypes/test/test_agilent.py" = ["F401", "F841"] -"comtypes/test/test_client.py" = ["F401"] +"comtypes/test/find_memleak.py" = ["E401", "F403", "F405"] +"comtypes/test/test_agilent.py" = ["F841"] "comtypes/test/test_dict.py" = ["F841"] "comtypes/test/test_eventinterface.py" = ["F841"] "comtypes/test/test_outparam.py" = ["F841"] "comtypes/test/test_sapi.py" = ["E401"] -"comtypes/test/test_server.py" = ["F401", "F841"] -"comtypes/test/test_subinterface.py" = ["E401", "F401", "F403", "F405"] -"comtypes/test/test_urlhistory.py" = ["E401", "F401", "F403", "F405", "F841"] -"comtypes/test/test_variant.py" = ["F401", "F821", "F841"] +"comtypes/test/test_server.py" = ["F841"] +"comtypes/test/test_subinterface.py" = ["E401", "F403", "F405"] +"comtypes/test/test_urlhistory.py" = ["E401", "F403", "F405", "F841"] +"comtypes/test/test_variant.py" = ["F821", "F841"] [tool.coverage.run] # Specify the source directory to avoid tracking temporary files created by "test_client_regenerate_modules.py".