Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion AutoDuck/makedfromi.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def GetComments(line, lineNo, lines):


def make_doc_summary(inFile, outFile):
methods = []
methods: list[tuple[str, list[str]]] = []
modDoc = ""
modName = ""
lines = inFile.readlines()
Expand Down
4 changes: 2 additions & 2 deletions AutoDuck/py2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def should_build_function(build_info):

# docstring aware paragraph generator. Isn't there something in docutils
# we can use?
def gen_paras(val):
chunks = []
def gen_paras(val: str):
chunks: list[str] = []
in_docstring = False
for line in val.splitlines():
line = ad_escape(line.strip())
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/debugger/dbgcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def DoGetOption(optsDict, optName, default):


def LoadDebuggerOptions():
opts = {}
opts: dict[str, str] = {}
DoGetOption(opts, OPT_HIDE, 0)
DoGetOption(opts, OPT_STOP_EXCEPTIONS, 1)
return opts
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def ListAllHelpFiles():
def _ListAllHelpFilesInRoot(root):
"""Returns a list of (helpDesc, helpFname) for all registered help files"""

retList = []
retList: list[tuple[str, str]] = []
try:
key = win32api.RegOpenKey(
root, regutil.BuildDefaultPythonKey() + "\\Help", 0, win32con.KEY_READ
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 @@ -482,7 +482,7 @@ def GetBlockBoundary(self, lineNo):

def ExtractCommand(self, lines):
start, end = lines
retList = []
retList: list[str] = []
while end >= start:
thisLine = self.DoGetLine(end)
promptLen = len(GetPromptPrefix(thisLine))
Expand Down
7 changes: 3 additions & 4 deletions Pythonwin/pywin/framework/scriptutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def ImportFile():
# meaning sys.modules can change as a side-effect of looking at
# module.__file__ - so we must take a copy (ie, list(items()))
for key, mod in sys.modules.items():
if getattr(mod, "__file__", None):
if hasattr(mod, "__file__") and mod.__file__:
fname = mod.__file__
base, ext = os.path.splitext(fname)
if ext.lower() in (".pyo", ".pyc"):
Expand Down Expand Up @@ -547,14 +547,13 @@ def RunTabNanny(filename):
data = newout.getvalue()
if data:
try:
lineno = data.split()[1]
lineno = int(lineno)
lineno = int(data.split()[1])
_JumpToPosition(filename, lineno)
try: # Try and display whitespace
GetActiveEditControl().SCISetViewWS(1)
except:
pass
win32ui.SetStatusText("The TabNanny found trouble at line %d" % lineno)
win32ui.SetStatusText(f"The TabNanny found trouble at line {lineno}")
except (IndexError, TypeError, ValueError):
print("The tab nanny complained, but I can't see where!")
print(data)
Expand Down
4 changes: 2 additions & 2 deletions Pythonwin/pywin/framework/winout.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def __init__(
self.iniSizeSection = None
self.defSize = defSize
self.currentView = None
self.outputQueue = queue.Queue(-1)
self.outputQueue: queue.Queue[str] = queue.Queue(-1)
self.mainThreadId = win32api.GetCurrentThreadId()
self.idleHandlerSet = 0
self.SetIdleHandler()
Expand Down Expand Up @@ -520,7 +520,7 @@ def QueueFlush(self, max=None):
self.currentView.dowrite("".join(items))
return rc

def HandleOutput(self, message):
def HandleOutput(self, message: str):
# debug("QueueOutput on thread %d, flags %d with '%s'...\n" % (win32api.GetCurrentThreadId(), self.writeQueueing, message ))
self.outputQueue.put(message)
if win32api.GetCurrentThreadId() != self.mainThreadId:
Expand Down
6 changes: 4 additions & 2 deletions Pythonwin/pywin/scintilla/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# .py file, and put the config info in a docstring. Then
# pass a CStringIO file (rather than a filename) to the
# config manager.
from __future__ import annotations

import glob
import importlib.util
import marshal
Expand Down Expand Up @@ -35,7 +37,7 @@ def trace(*args):
compiled_config_version = 3


def split_line(line, lineno):
def split_line(line: str, lineno: int):
comment_pos = line.find("#")
if comment_pos >= 0:
line = line[:comment_pos]
Expand Down Expand Up @@ -269,7 +271,7 @@ def _save_data(self, name, data):
return data

def _load_general(self, sub_section, fp, lineno):
map = {}
map: dict[str, list[str | None]] = {}
while 1:
line, lineno, bBreak = self._readline(fp, lineno)
if bBreak:
Expand Down
4 changes: 2 additions & 2 deletions Pythonwin/pywin/scintilla/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,8 @@ def _GetWordSplit(self, pos=-1, bAllowCalls=0):
if pos == -1:
pos = self.GetSel()[0] - 1 # Character before current one
limit = self.GetTextLength()
before = []
after = []
before: list[str] = []
after: list[str] = []
index = pos - 1
wordbreaks_use = wordbreaks
if bAllowCalls:
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/client/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def _make_method_(self, name):
# self._print_details_()
codeObject = compile(methodCode, "<COMObject %s>" % self._username_, "exec")
# Exec the code object
tempNameSpace = {}
tempNameSpace: dict[str, object] = {}
# "Dispatch" in the exec'd code is win32com.client.Dispatch, not ours.
globNameSpace = globals().copy()
globNameSpace["Dispatch"] = win32com.client.Dispatch
Expand Down
4 changes: 2 additions & 2 deletions com/win32comext/axdebug/codecontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _ProcessToken(self, type, token, spos, epos, line):
erow, ecol = epos
self.GetText() # Prime us.
linenum = srow - 1 # Lines zero based for us too.
realCharPos = self.lineOffsets[linenum] + scol
realCharPos: int = self.lineOffsets[linenum] + scol
numskipped = realCharPos - self.lastPos
if numskipped == 0:
pass
Expand Down Expand Up @@ -162,7 +162,7 @@ def _ProcessToken(self, type, token, spos, epos, line):

def GetSyntaxColorAttributes(self):
self.lastPos = 0
self.attrs = []
self.attrs: list[tuple[int] | tuple[int, int]] = []
try:
for tokens in tokenize.tokenize(self.GetNextLine):
self._ProcessToken(*tokens)
Expand Down
4 changes: 3 additions & 1 deletion com/win32comext/axscript/client/pyscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
command line.
"""

from __future__ import annotations

import re
import types

Expand Down Expand Up @@ -286,7 +288,7 @@ def GetScriptDispatch(self, name):
)
return self.scriptDispatch

def MakeEventMethodName(self, subItemName, eventName):
def MakeEventMethodName(self, subItemName: str, eventName: str):
return (
subItemName[0].upper()
+ subItemName[1:]
Expand Down
2 changes: 0 additions & 2 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ disable_error_code =
; list-item,
; operator,
; override,
; str-format,
; type-var,
; union-attr,
; valid-type,
; var-annotated,
; ; And these only happen when checking against types-pywin32
; func-returns-value,
Expand Down
23 changes: 12 additions & 11 deletions win32/Lib/win32pdhquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@
"""

# Feb 12, 98 - MH added "rawaddcounter" so caller can get exception details.
from __future__ import annotations

import _thread
import copy
import time
from itertools import chain

import win32api
import win32pdh
Expand Down Expand Up @@ -445,14 +447,11 @@ def getinstpaths(
cur += 1
except IndexError: # if we went over the end
pass
paths = []
for ind in range(len(temp)):
# can this raise an error?
paths.append(
win32pdh.MakeCounterPath(
(machine, "Process", object, None, ind, counter)
)
)
paths = [
win32pdh.MakeCounterPath((machine, "Process", object, None, ind, counter))
for ind in range(len(temp))
]

return paths # should also return the number of elements for naming purposes

def open(self, *args, **namedargs):
Expand All @@ -467,9 +466,11 @@ def open(self, *args, **namedargs):
# do all the normal opening stuff, self._base is now the query object
BaseQuery.open(*(self,) + args, **namedargs)
# should rewrite getinstpaths to take a single tuple
paths = []
for tup in self.volatilecounters:
paths[len(paths) :] = self.getinstpaths(*tup)
paths = list(
chain.from_iterable(
self.getinstpaths(*tup) for tup in self.volatilecounters
)
)
for path in paths:
try:
self.counters.append(win32pdh.AddCounter(self._base, path))
Expand Down
4 changes: 2 additions & 2 deletions win32/Lib/win32pdhutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def FindPerformanceAttributesByName(
instanceName = instanceName.lower()
items, instances = win32pdh.EnumObjectItems(None, None, object, -1)
# Track multiple instances.
instance_dict = {}
instance_dict: dict[str, int] = {}
for instance in instances:
try:
instance_dict[instance] += 1
Expand All @@ -125,7 +125,7 @@ def ShowAllProcesses():
None, None, object, win32pdh.PERF_DETAIL_WIZARD
)
# Need to track multiple instances of the same name.
instance_dict = {}
instance_dict: dict[str, int] = {}
for instance in instances:
try:
instance_dict[instance] += 1
Expand Down
19 changes: 10 additions & 9 deletions 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 @@ -449,8 +450,8 @@ def ControlService(serviceName, code, machine=None):
return status


def __FindSvcDeps(findName):
dict = {}
def __FindSvcDeps(findName: str):
deps_dict: dict[str, list[str]] = {}
k = win32api.RegOpenKey(
win32con.HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services"
)
Expand All @@ -468,19 +469,19 @@ def __FindSvcDeps(findName):
deps = ()
for dep in deps:
dep = dep.lower()
dep_on = dict.get(dep, [])
dep_on = deps_dict.get(dep, [])
dep_on.append(svc)
dict[dep] = dep_on
deps_dict[dep] = dep_on

return __ResolveDeps(findName, dict)
return __ResolveDeps(findName, deps_dict)


def __ResolveDeps(findName, dict):
items = dict.get(findName.lower(), [])
retList = []
def __ResolveDeps(findName: str, deps_dict: dict[str, list[str]]):
items = deps_dict.get(findName.lower(), [])
retList: list[str] = []
for svc in items:
retList.insert(0, svc)
retList = __ResolveDeps(svc, dict) + retList
retList = __ResolveDeps(svc, deps_dict) + retList
return retList


Expand Down