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

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Jul 28, 2024

See per-file comments for more details.

Some expanded star imports with lots of entries might be better as import x instead of from x import a, b, c, ...

Comment on lines +29 to +50
# 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
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.

@@ -100,4 +100,4 @@ def SetEditorFontOption(option, newValue):
SetEditorOption(option, str(newValue))


from pywin.framework.editor.color.coloreditor import editorTemplate
import pywin.framework.editor.color.coloreditor # nopycln: import # Adds doc template
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Assuming this side-effect is wanted here:

# For debugging purposes, when this module may be reloaded many times.
try:
win32ui.GetApp().RemoveDocTemplate(editorTemplate) # type: ignore[has-type, used-before-def]
except NameError:
pass
editorTemplate = SyntEditTemplate()
win32ui.GetApp().AddDocTemplate(editorTemplate)

Comment on lines +9 to +11
from . import ( # nopycln: import # Injects fast_readline into the IDLE auto-indent extension
IDLEenvironment,
)
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.

@@ -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.

Comment on lines +8 to +15
"pythoncom",
"pywintypes",
"win32api",
"win32clipboard",
"win32com",
"win32cryptcon",
"win32event",
"win32file",
"win32gui_struct",
"win32gui",
"win32inet",
"win32inetcon",
"win32pipe",
"win32ras",
"win32ui",
"win32process",
"win32security",
"win32uiole",
Copy link
Collaborator Author

@Avasam Avasam Jul 28, 2024

Choose a reason for hiding this comment

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

Do you know if any of these produce side-effects in a way one might want to import the module w/o using any of its symbols?

  "pythoncom",
  "pywintypes",
  "win32api",
  "win32file",
  "win32gui",
  "win32process",
  "win32security",
  "win32uiole",

@Avasam Avasam force-pushed the pycln-cleanup-more-imports branch from c88531e to b0490f2 Compare July 28, 2024 18:57
@Avasam Avasam changed the title pycln: automatic cleanup of more imports pycln: cleanup of more imports Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant