Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pycln: cleanup of more imports #2342

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion AutoDuck/TOCToHHK.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os.path
import sys

"""
Expand Down
48 changes: 23 additions & 25 deletions Pythonwin/pywin/Demos/guidemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import sys

import __main__
import regutil
import win32api
import win32ui

demos = [ # ('Font', 'import fontdemo;fontdemo.FontDemo()'),
demos = [
# ("Font", "import fontdemo;fontdemo.FontDemo()"),
("Open GL Demo", "import openGLDemo;openGLDemo.test()"),
("Threaded GUI", "import threadedgui;threadedgui.ThreadedDemo()"),
("Tree View Demo", "import hiertest;hiertest.demoboth()"),
Expand All @@ -26,30 +26,28 @@


def demo():
try:
# seeif I can locate the demo files.
import fontdemo
except ImportError:
# else put the demos direectory on the path (if not already)
try:
instPath = regutil.GetRegistryDefaultValue(
regutil.BuildDefaultPythonKey() + "\\InstallPath"
)
except win32api.error:
print(
"The InstallPath can not be located, and the Demos directory is not on the path"
)
instPath = "."

demosDir = win32ui.FullPath(instPath + "\\Demos")
for path in sys.path:
if win32ui.FullPath(path) == demosDir:
break
else:
sys.path.append(demosDir)
import fontdemo
# try:
# # seeif I can locate the demo files.
# import fontdemo
# except ImportError:
# # else put the demos direectory on the path (if not already)
# try:
# instPath = regutil.GetRegistryDefaultValue(
# regutil.BuildDefaultPythonKey() + "\\InstallPath"
# )
# except win32api.error:
# print(
# "The InstallPath can not be located, and the Demos directory is not on the path"
# )
# instPath = "."

import sys
# demosDir = win32ui.FullPath(instPath + "\\Demos")
# for path in sys.path:
# if win32ui.FullPath(path) == demosDir:
# break
# else:
# sys.path.append(demosDir)
# import fontdemo
Comment on lines +29 to +50
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The demo was already commented out above. TBD if fontdemo should just be removed entirely from here or added back in. It's possible that #2101 fixed w/e issue fontdemo had.


if "/go" in sys.argv:
for name, cmd in demos:
Expand Down
2 changes: 0 additions & 2 deletions Pythonwin/pywin/framework/bitmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import win32ui
from pywin.mfc import docview, window

from . import app

bStretch = 1


Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/editor/ModuleBrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import win32con
import win32ui
from pywin.mfc import afxres
from pywin.tools import browser, hierlist
from pywin.tools import hierlist


class HierListCLBRModule(hierlist.HierListItem):
Expand Down
4 changes: 3 additions & 1 deletion Pythonwin/pywin/framework/editor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,6 @@ def SetEditorFontOption(option, newValue):
SetEditorOption(option, str(newValue))


from pywin.framework.editor.color.coloreditor import editorTemplate
from pywin.framework.editor.color.coloreditor import ( # nopycln: import
editorTemplate as editorTemplate, # Adds doc template & Re-export
)
1 change: 0 additions & 1 deletion Pythonwin/pywin/framework/editor/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import win32con
import win32ui
from pywin.framework.editor import GetEditorOption
from pywin.mfc import docview, object

BAK_NONE = 0
BAK_DOT_BAK = 1
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import pywin.framework.app
import pywin.scintilla.control
import pywin.scintilla.formatter
import pywin.scintilla.IDLEenvironment
import pywin.scintilla.IDLEenvironment # nopycln: import # Injects fast_readline into the IDLE auto-indent extension
import win32api
import win32clipboard
import win32con
Expand Down
8 changes: 7 additions & 1 deletion Pythonwin/pywin/framework/intpydde.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@

import win32api
import win32ui
from dde import *
from dde import ( # nopycln: import # Re-exported for intpyapp.py
CBF_FAIL_SELFCONNECTIONS as CBF_FAIL_SELFCONNECTIONS, # noqa: PLC0414
CreateConversation as CreateConversation, # noqa: PLC0414
CreateServer,
CreateServerSystemTopic,
error as error, # noqa: PLC0414
)
from pywin.mfc import object


Expand Down
2 changes: 0 additions & 2 deletions Pythonwin/pywin/framework/toolmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import win32con
import win32ui

from . import app

tools = {}
idPos = 100

Expand Down
4 changes: 3 additions & 1 deletion Pythonwin/pywin/scintilla/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import win32con
import win32ui

from . import IDLEenvironment, keycodes
from . import ( # nopycln: import # Injects fast_readline into the IDLE auto-indent extension
IDLEenvironment,
)
Comment on lines +9 to +11
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If injecting in the extension isn't needed when IDLEenvironment isn't used directly (it's imported in a couple other places), then this can be removed.


HANDLER_ARGS_GUESS = 0
HANDLER_ARGS_NATIVE = 1
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/scintilla/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pywin.mfc import afxres, docview

from . import (
IDLEenvironment, # IDLE emulation.
IDLEenvironment, # nopycln: import # Injects fast_readline into the IDLE auto-indent extension
bindings,
control,
scintillacon,
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/test/test_pywin.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def test_ia(self):
def test_docedit(self):
import tempfile

import pywin.scintilla.IDLEenvironment
import pywin.scintilla.IDLEenvironment # nopycln: import # Injects fast_readline into the IDLE auto-indent extension

##doc = pywin.framework.editor.editorTemplate.OpenDocumentFile(None)
def t_print(*args):
Expand Down
1 change: 1 addition & 0 deletions adodbapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# nopycln: file # undecidable cases due to explicit re-exports https://github.com/hadialqattan/pycln/issues/205
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""adodbapi - A python DB API 2.0 (PEP 249) interface to Microsoft ADO

Copyright (C) 2002 Henrik Ekelund, version 2.1 by Vernon Cole
Expand Down
1 change: 0 additions & 1 deletion adodbapi/test/adodbapitest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import adodbapitestconfig as config # run the configuration module. # will set sys.path to find correct version of adodbapi
import tryconnection # in our code below, all our switches are from config.whatever
import win32com.client

import adodbapi
import adodbapi.apibase as api
Expand Down
3 changes: 0 additions & 3 deletions com/win32com/client/combrowse.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ def CalculateIsExpandable(self):
rc = 0
return rc

pass


class HLI_IEnumMoniker(HLI_Enum):
def GetSubList(self):
Expand Down Expand Up @@ -595,7 +593,6 @@ def GetSubList(self):


def main(modal=True, mdi=False):
from pywin.tools import hierlist

root = HLIRoot("COM Browser")
if mdi and "pywin.framework.app" in sys.modules:
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/client/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

import pythoncom
from win32com.client import Dispatch, _get_good_object_
from win32com.client import _get_good_object_

PyIDispatchType = pythoncom.TypeIIDs[pythoncom.IID_IDispatch]

Expand Down
2 changes: 1 addition & 1 deletion com/win32com/demos/excelAddin.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

import pythoncom
from win32com import universal
from win32com.client import Dispatch, DispatchWithEvents, constants, gencache
from win32com.client import DispatchWithEvents, constants, gencache

# Support for COM objects we use.
gencache.EnsureModule(
Expand Down
3 changes: 0 additions & 3 deletions com/win32com/demos/iebutton.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import win32api
import win32com
import win32com.server.register
from win32com import universal
from win32com.client import Dispatch, DispatchWithEvents, constants, gencache, getevents

# This demo uses 'print' - use win32traceutil to see it if we have no
# console.
Expand All @@ -40,7 +38,6 @@
except win32api.error:
import win32traceutil

import array

from win32com.axcontrol import axcontrol

Expand Down
2 changes: 1 addition & 1 deletion com/win32com/server/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def _HandleException_(self):


try:
import win32trace
import win32trace # nopycln: import # Check for win32traceutil w/o importing it

DefaultDebugDispatcher: type[DispatcherTrace] = DispatcherWin32trace
except ImportError: # no win32trace module - just use a print based one.
Expand Down
9 changes: 6 additions & 3 deletions com/win32com/server/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@
problem, rather than a COM error.
"""

__author__ = "Greg Stein and Mark Hammond"

import sys
import types

Expand All @@ -92,6 +90,8 @@

from .exception import COMException

__author__ = "Greg Stein and Mark Hammond"

S_OK = 0

# Few more globals to speed things.
Expand Down Expand Up @@ -812,6 +812,9 @@ def _import_module(mname):
# These have been moved to a new source file, but some code may
# still reference them here. These will end up being removed.
try:
from .dispatcher import DispatcherTrace, DispatcherWin32trace
from .dispatcher import ( # nopycln: import
DispatcherTrace as DispatcherTrace, # noqa: PLC0414 # Explicit re-export of unused symbol
DispatcherWin32trace as DispatcherWin32trace, # noqa: PLC0414 # Explicit re-export of unused symbol
)
except ImportError: # Quite likely a frozen executable that doesn't need dispatchers
pass
1 change: 0 additions & 1 deletion com/win32com/servers/test_pycomtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import winerror

# Ensure the vtables in the tlb are known.
from win32com import universal
from win32com.client import constants, gencache
from win32com.server.exception import COMException
from win32com.server.util import wrap
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/test/testADOEvents.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time

import pythoncom
from win32com.client import Dispatch, DispatchWithEvents, constants
from win32com.client import DispatchWithEvents, constants

finished = 0 # Flag for the wait loop from (3) to test

Expand Down
3 changes: 1 addition & 2 deletions com/win32com/test/testAXScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ def setUp(self):
file = win32api.GetFullPathName(
os.path.join(next(iter(win32com.axscript.client.__path__)), "pyscript.py")
)
from win32com.test.util import RegisterPythonServer

self.verbose = verbose
RegisterPythonServer(file, "python", verbose=self.verbose)
win32com.test.util.RegisterPythonServer(file, "python", verbose=self.verbose)

def testHost(self):
file = win32api.GetFullPathName(
Expand Down
5 changes: 3 additions & 2 deletions com/win32com/test/testDictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ def TestDictAgainst(dict, check):
# Ensure we have the correct version registered.
def Register(quiet):
import win32com.servers.dictionary
from win32com.test.util import RegisterPythonServer

RegisterPythonServer(win32com.servers.dictionary.__file__, "Python.Dictionary")
win32com.test.util.RegisterPythonServer(
win32com.servers.dictionary.__file__, "Python.Dictionary"
)


def TestDict(quiet=None):
Expand Down
3 changes: 1 addition & 2 deletions com/win32com/test/testExchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os

import pythoncom
from win32com.client import constants, gencache
from win32com.client import gencache

ammodule = None # was the generated module!

Expand Down Expand Up @@ -94,7 +94,6 @@ def TestUser(session):


def test():
import win32com.client

oldcwd = os.getcwd()
try:
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/test/testMSOffice.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def TestAll():
traceback.print_exc()

try:
import xl5en32
import xl5en32 # nopycln: import # Test import. TODO: Is testing Excel 95 still relevant ?

mod = gencache.EnsureModule("{00020813-0000-0000-C000-000000000046}", 9, 1, 0)
xl = win32com.client.Dispatch("Excel.Application.5")
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/test/testMSOfficeEvents.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import types

import pythoncom
from win32com.client import Dispatch, DispatchWithEvents
from win32com.client import DispatchWithEvents

stopEvent = threading.Event()

Expand Down
4 changes: 2 additions & 2 deletions com/win32com/test/testPyComTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
import win32api
import win32com
import win32com.client.connect
import win32com.test.util
import win32timezone
import winerror
from win32com.client import VARIANT, CastTo, DispatchBaseClass, constants
from win32com.test.util import RegisterPythonServer

importMsg = "**** PyCOMTest is not installed ***\n PyCOMTest is a Python test specific COM client and server.\n It is likely this server is not installed on this machine\n To install the server, you must get the win32com sources\n and build it using MS Visual C++"

# This test uses a Python implemented COM server - ensure correctly registered.
RegisterPythonServer(
win32com.test.util.RegisterPythonServer(
os.path.join(os.path.dirname(__file__), "..", "servers", "test_pycomtest.py"),
"Python.Test.PyCOMTest",
)
Expand Down
3 changes: 1 addition & 2 deletions com/win32com/test/testServers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ class InterpCase(win32com.test.util.TestCase):
def setUp(self):
# Ensure the correct version registered.
from win32com.servers import interp
from win32com.test.util import RegisterPythonServer

RegisterPythonServer(interp.__file__, "Python.Interpreter")
win32com.test.util.RegisterPythonServer(interp.__file__, "Python.Interpreter")

def _testInterp(self, interp):
self.assertEqual(interp.Eval("1+1"), 2)
Expand Down
3 changes: 1 addition & 2 deletions com/win32com/test/testall.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@

import pythoncom
import win32com.client
from pywin32_testutil import TestLoader, TestRunner
from win32com.test.util import (
CapturingFunctionTestCase,
CheckClean,
RegisterPythonServer,
ShellTestCase,
TestCase,
TestLoader,
TestRunner,
)

verbosity = 1 # default unittest verbosity.
Expand Down
Loading
Loading