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

Merged
merged 6 commits into from
Oct 13, 2024
Merged

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

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

pycln.toml Outdated
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",

Copy link
Owner

Choose a reason for hiding this comment

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

pywintypes might for the loader, but I don't think the rest do.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Noted. I'd like to merge this PR as-is w/o tackling additional changes in Python files, so I added it to the comment.

@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
com/win32com/test/testMSOffice.py Show resolved Hide resolved
pycln.toml Outdated
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
Owner

Choose a reason for hiding this comment

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

pywintypes might for the loader, but I don't think the rest do.

@Avasam Avasam merged commit 41da8be into mhammond:main Oct 13, 2024
31 checks passed
@Avasam Avasam deleted the pycln-cleanup-more-imports branch October 13, 2024 23:43
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.

2 participants