Skip to content

Commit

Permalink
Extracted annotations only changes from mhammond#2102
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Feb 5, 2024
1 parent 93426ff commit 26c13ed
Show file tree
Hide file tree
Showing 24 changed files with 60 additions and 29 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ jobs:
path: |
dist/*.whl
# This job can be run locally with the `format_all.bat` script
checkers:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/bitmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def MatchDocType(self, fileName, fileType):

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

Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/editor/color/coloreditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ def GetPythonPropertyPages(self):

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

Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/editor/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def Create(fileName=None, title=None, template=None):
if __name__ == prefModule:
# For debugging purposes, when this module may be reloaded many times.
try:
win32ui.GetApp().RemoveDocTemplate(editorTemplate)
win32ui.GetApp().RemoveDocTemplate(editorTemplate) # type: ignore[has-type, used-before-def]
except (NameError, win32ui.error):
pass

Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/mdi_pychecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ def getNew(self):


try:
win32ui.GetApp().RemoveDocTemplate(greptemplate)
win32ui.GetApp().RemoveDocTemplate(greptemplate) # type: ignore[has-type, used-before-def]
except NameError:
pass

Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/sgrepmdi.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ def getNew(self):


try:
win32ui.GetApp().RemoveDocTemplate(greptemplate)
win32ui.GetApp().RemoveDocTemplate(greptemplate) # type: ignore[has-type, used-before-def]
except NameError:
pass

Expand Down
6 changes: 4 additions & 2 deletions Pythonwin/pywin/scintilla/bindings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import traceback

import win32api
Expand All @@ -13,8 +15,8 @@

next_id = 5000

event_to_commands = {} # dict of integer IDs to event names.
command_to_events = {} # dict of event names to int IDs
event_to_commands: dict[str, int] = {} # dict of event names to IDs
command_to_events: dict[int, str] = {} # dict of IDs to event names


def assign_command_id(event, id=0):
Expand Down
4 changes: 3 additions & 1 deletion Pythonwin/pywin/scintilla/find.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# find.py - Find and Replace
from __future__ import annotations

import afxres
import win32api
import win32con
Expand Down Expand Up @@ -35,7 +37,7 @@ def __setattr__(self, attr, val):

curDialog = None
lastSearch = defaultSearch = SearchParams()
searchHistory = []
searchHistory: list[str] = []


def ShowFindDialog():
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/tools/browseProjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def GetText(self):


class HLICLBRItem(hierlist.HierListItem):
def __init__(self, name, file, lineno, suffix=""):
def __init__(self, name: str, file, lineno, suffix=""):
# If the 'name' object itself has a .name, use it. Not sure
# how this happens, but seems pyclbr related.
# See PyWin32 bug 817035
Expand Down
11 changes: 8 additions & 3 deletions com/win32com/client/gencache.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@
Maybe an OLE2 compound file, or a bsddb file?
"""

from __future__ import annotations

import glob
import os
import sys
from importlib import reload
from types import ModuleType
from typing import Any

import pythoncom
import pywintypes
Expand All @@ -36,11 +40,11 @@
bForDemandDefault = 0 # Default value of bForDemand - toggle this to change the world - see also makepy.py

# The global dictionary
clsidToTypelib = {}
clsidToTypelib: dict[str, tuple[str, int, int, int]] = {}

# If we have a different version of the typelib generated, this
# maps the "requested version" to the "generated version".
versionRedirectMap = {}
versionRedirectMap: dict[tuple[str, int, int, int], ModuleType | None] = {}

# There is no reason we *must* be readonly in a .zip, but we are now,
# Rather than check for ".zip" or other tricks, PEP302 defines
Expand All @@ -53,7 +57,8 @@

# A dictionary of ITypeLibrary objects for demand generation explicitly handed to us
# Keyed by usual clsid, lcid, major, minor
demandGeneratedTypeLibraries = {}
# Typing as Any because PyITypeLib is not exposed
demandGeneratedTypeLibraries: dict[tuple[str, int, int, int], Any] = {}

import pickle as pickle

Expand Down
4 changes: 3 additions & 1 deletion com/win32com/server/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Please see policy.py for a discussion on dispatchers and policies
"""

from __future__ import annotations

import traceback
from sys import exc_info

Expand Down Expand Up @@ -284,6 +286,6 @@ def _HandleException_(self):
try:
import win32trace

DefaultDebugDispatcher = DispatcherWin32trace
DefaultDebugDispatcher: type[DispatcherTrace] = DispatcherWin32trace
except ImportError: # no win32trace module - just use a print based one.
DefaultDebugDispatcher = DispatcherTrace
1 change: 1 addition & 0 deletions com/win32com/test/testvb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#

import traceback
from collections.abc import Callable

import pythoncom
import win32com.client
Expand Down
1 change: 1 addition & 0 deletions com/win32comext/adsi/demos/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
from collections.abc import Callable

import pythoncom
import win32api
Expand Down
4 changes: 3 additions & 1 deletion com/win32comext/axscript/client/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
There are classes defined for the engine itself, and for ScriptItems
"""

from __future__ import annotations

import re
import sys

Expand Down Expand Up @@ -175,7 +177,7 @@ def Build(self, typeinfo, funcdesc):
class EventSink:
"""A set of events against an item. Note this is a COM client for connection points."""

_public_methods_ = []
_public_methods_: list[str] = []

def __init__(self, myItem, coDispatch):
self.events = {}
Expand Down
4 changes: 3 additions & 1 deletion com/win32comext/axscript/client/scriptdispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
this yet, so it is not well tested!
"""

from __future__ import annotations

import types

import pythoncom
Expand All @@ -26,7 +28,7 @@ def _is_callable(obj):


class ScriptDispatch:
_public_methods_ = []
_public_methods_: list[str] = []

def __init__(self, engine, scriptNamespace):
self.engine = engine
Expand Down
8 changes: 5 additions & 3 deletions com/win32comext/mapi/mapiutil.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# General utilities for MAPI and MAPI objects.
from __future__ import annotations

import pythoncom
from pywintypes import TimeType

from . import mapi, mapitags

prTable = {}
prTable: dict[int, str] = {}


def GetPropTagName(pt):
Expand Down Expand Up @@ -57,7 +59,7 @@ def GetPropTagName(pt):
return ret


mapiErrorTable = {}
mapiErrorTable: dict[int, str] = {}


def GetScodeString(hr):
Expand All @@ -68,7 +70,7 @@ def GetScodeString(hr):
return mapiErrorTable.get(hr, pythoncom.GetScodeString(hr))


ptTable = {}
ptTable: dict[int, str] = {}


def GetMapiTypeName(propType, rawType=True):
Expand Down
8 changes: 5 additions & 3 deletions isapi/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# this code adapted from "Tomcat JK2 ISAPI redirector", part of Apache
# Created July 2004, Mark Hammond.
from __future__ import annotations

import importlib.machinery
import os
import shutil
Expand Down Expand Up @@ -73,7 +75,7 @@ class VirtualDirParameters:
EnableDirBrowsing = _DEFAULT_ENABLE_DIR_BROWSING
EnableDefaultDoc = _DEFAULT_ENABLE_DEFAULT_DOC
DefaultDoc = None # Only set in IIS if not None
ScriptMaps = []
ScriptMaps: list[ScriptMapParams] = []
ScriptMapUpdate = "end" # can be 'start', 'end', 'replace'
Server = None

Expand Down Expand Up @@ -117,8 +119,8 @@ def __str__(self):
class ISAPIParameters:
ServerName = _DEFAULT_SERVER_NAME
# Description = None
Filters = []
VirtualDirs = []
Filters: list[FilterParameters] = []
VirtualDirs: list[VirtualDirParameters] = []

def __init__(self, **kw):
self.__dict__.update(kw)
Expand Down
2 changes: 1 addition & 1 deletion isapi/samples/advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
from isapi import InternalReloadException

try:
reload_counter += 1
reload_counter += 1 # type: ignore[used-before-def]
except NameError:
reload_counter = 0

Expand Down
4 changes: 3 additions & 1 deletion isapi/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
must ensure each of the required methods are implemented.
"""

from __future__ import annotations


class SimpleExtension:
"Base class for a simple ISAPI extension"
Expand Down Expand Up @@ -38,7 +40,7 @@ def TerminateExtension(self, status):

class SimpleFilter:
"Base class for a a simple ISAPI filter"
filter_flags = None
filter_flags: int | None = None

def __init__(self):
pass
Expand Down
4 changes: 2 additions & 2 deletions pywin32_postinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def flush(self):
# functions which write lines to PythonXX\pywin32-install.log. This is
# a list of actions for the uninstaller, the format is inspired by what
# the Wise installer also creates.
file_created
file_created # type: ignore[used-before-def]
# 3.10 stopped supporting bdist_wininst, but we can still build them with 3.9.
# This can be kept until Python 3.9 or exe installers support is dropped.
is_bdist_wininst = True
Expand All @@ -98,7 +98,7 @@ def get_root_hkey():


try:
create_shortcut
create_shortcut # type: ignore[used-before-def]
except NameError:
# Create a function with the same signature as create_shortcut provided
# by bdist_wininst
Expand Down
4 changes: 3 additions & 1 deletion win32/Lib/win32pdhutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
the easiest way is often to simply use PerfMon to find out the names.
"""

from __future__ import annotations

import time

import win32pdh
Expand All @@ -27,7 +29,7 @@
# Handle some localization issues.
# see http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q287/1/59.asp&NoWebContent=1
# Build a map of english_counter_name: counter_id
counter_english_map = {}
counter_english_map: dict[str, int] = {}


def find_pdh_counter_localized_name(english_name, machine_name=None):
Expand Down
6 changes: 4 additions & 2 deletions win32/Lib/win32rcparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
This is a parser for Windows .rc files, which are text files which define
dialogs and other Windows UI resources.
"""
from __future__ import annotations

__author__ = "Adam Walker"
__version__ = "0.11"

Expand Down Expand Up @@ -171,8 +173,8 @@ def __repr__(self):

class RCParser:
next_id = 1001
dialogs = {}
_dialogs = {}
dialogs: dict[str, list[list[str | int | None | tuple[str | int, ...]]]] = {}
_dialogs: dict[str, DialogDef] = {}
debugEnabled = False
token = ""

Expand Down
4 changes: 3 additions & 1 deletion win32/Lib/win32timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@
datetime.datetime(2011, 11, 6, 1, 0, tzinfo=TimeZoneInfo('Pacific Standard Time'))
"""
from __future__ import annotations

__author__ = "Jason R. Coombs <[email protected]>"

import datetime
Expand All @@ -249,7 +251,7 @@
# A couple of objects for working with objects as if they were native C-type
# structures.
class _SimpleStruct:
_fields_ = None # must be overridden by subclasses
_fields_: list[tuple[str, type]] | None = None # must be overridden by subclasses

def __init__(self, *args, **kw):
for i, (name, typ) in enumerate(self._fields_):
Expand Down
1 change: 1 addition & 0 deletions win32/scripts/ce/pysynch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import getopt
import os
import sys
from collections.abc import Callable

import win32api
import win32con
Expand Down

0 comments on commit 26c13ed

Please sign in to comment.