From 0a5a6ad86ced8911806634179950d9f19050d583 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 28 Feb 2024 11:30:58 -0500 Subject: [PATCH] Solve some pyright warnings in changed files --- Pythonwin/pywin/framework/stdin.py | 2 +- pyrightconfig.json | 2 +- pywin32_postinstall.py | 25 ++++++++++--------------- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/Pythonwin/pywin/framework/stdin.py b/Pythonwin/pywin/framework/stdin.py index 20e1b094bd..91fe7ef3e1 100644 --- a/Pythonwin/pywin/framework/stdin.py +++ b/Pythonwin/pywin/framework/stdin.py @@ -168,4 +168,4 @@ def fake_input(prompt=None): finally: get_input_line = input else: - sys.stdin = Stdin() # type: ignore[assignment] + sys.stdin = Stdin() # type: ignore[assignment] # Not an actual TextIO diff --git a/pyrightconfig.json b/pyrightconfig.json index 1b68253a1c..1dd371af23 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -32,7 +32,7 @@ "reportArgumentType": "none", "reportAttributeAccessIssue": "none", // FIXE: These all need to be fixed first and turned back to error - // spme of the fixes need to be done in types-pywin32 from typeshed + // some of the fixes need to be done in types-pywin32 from typeshed "reportAssignmentType": "warning", "reportCallIssue": "warning", "reportIndexIssue": "warning", diff --git a/pywin32_postinstall.py b/pywin32_postinstall.py index f81c00e231..f8f790b59d 100644 --- a/pywin32_postinstall.py +++ b/pywin32_postinstall.py @@ -2,19 +2,14 @@ # # copies pywintypesXX.dll and pythoncomXX.dll into the system directory, # and creates a pth file +import argparse import glob import os import shutil import sys import sysconfig - -try: - import winreg as winreg -except: - import winreg - -# Send output somewhere so it can be found if necessary... -import tempfile +import tempfile # Send output somewhere so it can be found if necessary... +import winreg tee_f = open(os.path.join(tempfile.gettempdir(), "pywin32_postinstall.log"), "w") @@ -44,11 +39,11 @@ def flush(self): # with sys.stdout as None but stderr is hooked up. This work-around allows # bdist_wininst to see the output we write and display it at the end of # the install. -if sys.stdout is None: +if sys.stdout is None: # pyright: ignore[reportUnnecessaryComparison] sys.stdout = sys.stderr -sys.stderr = Tee(sys.stderr) # type: ignore[assignment] -sys.stdout = Tee(sys.stdout) # type: ignore[assignment] +sys.stderr = Tee(sys.stderr) # type: ignore[assignment] # Not an actual TextIO +sys.stdout = Tee(sys.stdout) # type: ignore[assignment] # Not an actual TextIO com_modules = [ # module_name, class_names @@ -161,7 +156,7 @@ def CopyTo(desc, src, dest): "If you have any Python applications running, " f"please close them now\nand select 'Retry'\n\n{details.strerror}" ) - rc = win32api.MessageBox( + rc = win32api.MessageBox( # pyright: ignore[reportCallIssue] # FIXME in typeshed stubs 0, full_desc, "Installation Error", win32con.MB_ABORTRETRYIGNORE ) if rc == win32con.IDABORT: @@ -193,7 +188,9 @@ def LoadSystemModule(lib_dir, modname): loader = importlib.machinery.ExtensionFileLoader(modname, filename) spec = importlib.machinery.ModuleSpec(name=modname, loader=loader, origin=filename) mod = importlib.util.module_from_spec(spec) - spec.loader.exec_module(mod) + spec.loader.exec_module( # pyright: ignore[reportOptionalMemberAccess] # We provide the loader, we know it won't be None + mod + ) def SetPyKeyVal(key_name, value_name, value): @@ -697,8 +694,6 @@ def verify_destination(location): def main(): - import argparse - parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description="""A post-install script for the pywin32 extensions.