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

Annotate ambiguous global variables #2323

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
8 changes: 7 additions & 1 deletion Pythonwin/pywin/debugger/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from __future__ import annotations

import sys
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from . import debugger

isInprocApp = -1

Expand Down Expand Up @@ -29,7 +35,7 @@ def _CheckNeedGUI():


# Inject some methods in the top level name-space.
currentDebugger = None # Wipe out any old one on reload.
currentDebugger: debugger.Debugger | None = None # Wipe out any old one on reload.


def _GetCurrentDebugger():
Expand Down
5 changes: 3 additions & 2 deletions Pythonwin/pywin/framework/help.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# help.py - help utilities for PythonWin.
from __future__ import annotations

import os

import regutil
Expand Down Expand Up @@ -122,7 +124,7 @@ def SelectAndRunHelpFile():
OpenHelpFile(helpFiles[index][1])


helpIDMap = None
helpIDMap: dict[int, tuple[str, str]] | None = None


def SetHelpMenuOtherHelp(mainMenu):
Expand All @@ -144,7 +146,6 @@ def SetHelpMenuOtherHelp(mainMenu):
if desc in excludeList:
excludeFnames.append(fname)

helpDescs = []
for desc, fname in firstList:
if fname not in excludeFnames:
helpIDMap[cmdID] = (desc, fname)
Expand Down
10 changes: 5 additions & 5 deletions Pythonwin/pywin/framework/interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
##
## Interactive Shell Window
##
from __future__ import annotations

import array
import code
import os
import re
import string
import sys
import traceback
Expand All @@ -21,16 +23,14 @@
import win32ui
from pywin.mfc import afxres

from . import winout

## sequential after ID_GOTO_LINE defined in editor.py
ID_EDIT_COPY_CODE = 0xE2002
ID_EDIT_EXEC_CLIPBOARD = 0x2003

trace = pywin.scintilla.formatter.trace

import re

from . import winout

# from IDLE.
_is_block_opener = re.compile(r":\s*(#.*)?$").search
_is_block_closer = re.compile(
Expand Down Expand Up @@ -899,7 +899,7 @@ def CreateDockedInteractiveWindow():
InteractiveDocument = winout.WindowOutputDocument

# We remember our one and only interactive window in the "edit" variable.
edit = None
edit: CInteractivePython | None = None


def CreateInteractiveWindowUserPreference(makeDoc=None, makeFrame=None):
Expand Down
14 changes: 6 additions & 8 deletions Pythonwin/pywin/framework/toolmenu.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# toolmenu.py
from __future__ import annotations

import sys

import win32api
import win32con
import win32ui

from . import app

tools = {}
tools: dict[int, tuple[str, str, str]] = {}
idPos = 100

# The default items should no tools menu exist in the INI file.
Expand Down Expand Up @@ -115,7 +113,7 @@ def HandleToolCommand(cmd, code):

global tools
(menuString, pyCmd, desc) = tools[cmd]
win32ui.SetStatusText("Executing tool %s" % desc, 1)
win32ui.SetStatusText(f"Executing tool {desc}", 1)
pyCmd = re.sub(r"\\n", "\n", pyCmd)
win32ui.DoWaitCursor(1)
oldFlag = None
Expand All @@ -126,13 +124,13 @@ def HandleToolCommand(cmd, code):
pass

try:
exec("%s\n" % pyCmd)
exec(f"{pyCmd}\n")
worked = 1
except SystemExit:
# The program raised a SystemExit - ignore it.
worked = 1
except:
print("Failed to execute command:\n%s" % pyCmd)
print(f"Failed to execute command:\n{pyCmd}")
traceback.print_exc()
worked = 0
if oldFlag is not None:
Expand All @@ -141,7 +139,7 @@ def HandleToolCommand(cmd, code):
if worked:
text = "Completed successfully."
else:
text = "Error executing %s." % desc
text = f"Error executing {desc}."
win32ui.SetStatusText(text, 1)


Expand Down
6 changes: 5 additions & 1 deletion win32/Lib/win32serviceutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# (which is win32service.error, pywintypes.error, etc)
# when things go wrong - eg, not enough permissions to hit the
# registry etc.
from __future__ import annotations

import importlib.machinery
import os
Expand Down Expand Up @@ -572,6 +573,9 @@ def RestartService(serviceName, args=None, waitSeconds=30, machine=None):
print("Gave up waiting for the old service to stop!")


g_debugService: ServiceFramework | None = None


def _DebugCtrlHandler(evt):
if evt in (win32con.CTRL_C_EVENT, win32con.CTRL_BREAK_EVENT):
assert g_debugService
Expand All @@ -581,7 +585,7 @@ def _DebugCtrlHandler(evt):
return False


def DebugService(cls, argv=[]):
def DebugService(cls: type[ServiceFramework], argv=[]):
# Run a service in "debug" mode. Re-implements what pythonservice.exe
# does when it sees a "-debug" param.
# Currently only used by "frozen" (ie, py2exe) programs (but later may
Expand Down
Loading