diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9e07b4c349..69386c5100 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -164,7 +164,7 @@ jobs: cache-dependency-path: .github/workflows/main.yml check-latest: true # pyright vendors typeshed, but let's make sure we have the most up to date stubs - - run: pip install types-setuptools PyOpenGL + - run: pip install types-setuptools PyOpenGL types-pywin32 - uses: jakebailey/pyright-action@v2 with: python-version: ${{ matrix.python-version }} diff --git a/com/win32comext/adsi/__init__.py b/com/win32comext/adsi/__init__.py index 16afd3b784..db38686756 100644 --- a/com/win32comext/adsi/__init__.py +++ b/com/win32comext/adsi/__init__.py @@ -1,3 +1,5 @@ +from typing import TYPE_CHECKING + import win32com import win32com.client @@ -6,7 +8,11 @@ import sys try: - import adsi + if TYPE_CHECKING: + # Get the name from typeshed stubs + from win32comext.adsi import adsi + else: + import adsi sys.modules["win32com.adsi.adsi"] = adsi except ImportError: @@ -21,11 +27,15 @@ # helpers. # Of specific note - most of the interfaces supported by ADSI -# derive from IDispatch - thus, you get the custome methods from the +# derive from IDispatch - thus, you get the custom methods from the # interface, as well as via IDispatch. import pythoncom -from .adsi import * # nopycln: import # Re-export everything from win32comext/adsi/adsi.pyd +if TYPE_CHECKING: + # Get the names from typeshed stubs + from win32comext.adsi.adsi import * # nopycln: import # pyright: ignore[reportAssignmentType,reportWildcardImportFromLibrary] +else: + from .adsi import * # nopycln: import # Re-export everything from win32comext/adsi/adsi.pyd LCID = 0 diff --git a/com/win32comext/axdebug/codecontainer.py b/com/win32comext/axdebug/codecontainer.py index fdcaf6b64d..5bccf9c472 100644 --- a/com/win32comext/axdebug/codecontainer.py +++ b/com/win32comext/axdebug/codecontainer.py @@ -257,7 +257,8 @@ def GetName(self, dnt): if __name__ == "__main__": - from Test import ttest + # local untyped module (improved by https://github.com/mhammond/pywin32/pull/2282) + from Test import ttest # pyright: ignore[reportMissingImports] sc = SourceModuleContainer(ttest) # sc = SourceCodeContainer(open(sys.argv[1], "rb").read(), sys.argv[1]) diff --git a/com/win32comext/mapi/__init__.py b/com/win32comext/mapi/__init__.py index 181ae1c5c7..261abecf2a 100644 --- a/com/win32comext/mapi/__init__.py +++ b/com/win32comext/mapi/__init__.py @@ -1,15 +1,25 @@ +from typing import TYPE_CHECKING + if isinstance(__path__, str): # For freeze to work! import sys try: - import mapi + if TYPE_CHECKING: + # Get the name from typeshed stubs + from win32comext.mapi import mapi + else: + import mapi sys.modules["win32com.mapi.mapi"] = mapi except ImportError: pass try: - import exchange + if TYPE_CHECKING: + # Get the name from typeshed stubs + from win32comext.mapi import exchange + else: + import exchange sys.modules["win32com.mapi.exchange"] = exchange except ImportError: diff --git a/mypy.ini b/mypy.ini index 4a0942b3a0..481013a76e 100644 --- a/mypy.ini +++ b/mypy.ini @@ -60,7 +60,7 @@ exclude = (?x)( ) ; C-modules that will need type-stubs -[mypy-adsi.*,dde,exchange,mapi,perfmon,servicemanager,win32api,win32console,win32clipboard,win32comext.adsi.adsi,win32event,win32evtlog,win32file,win32gui,win32help,win32pdh,win32process,win32ras,win32security,win32service,win32trace,win32ui,win32uiole,win32wnet,_win32sysloader,_winxptheme] +[mypy-dde,perfmon,servicemanager,win32api,win32console,win32clipboard,win32comext.adsi.adsi,win32event,win32evtlog,win32file,win32gui,win32help,win32pdh,win32process,win32ras,win32security,win32service,win32trace,win32ui,win32uiole,win32wnet,_win32sysloader,_winxptheme] ignore_missing_imports = True ; Most of win32com re-exports win32comext diff --git a/pyrightconfig.json b/pyrightconfig.json index 7cd19c5db0..5ce976c08b 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -41,8 +41,6 @@ "reportOptionalSubscript": "warning", // Needs fixes in types-pywin32 and requires Python 3.8 to annotate ambiguous global variables "reportUnnecessaryComparison": "warning", - // Too many dynamically generated modules. This will require type stubs to properly fix. - "reportMissingImports": "warning", // IDEM, but happens when pywin32 is not in site-packages but module is found from typeshed. // TODO: Is intended to be fixed with an editable install // Since we're a library, and not user code, we care less about forgetting to install a dependency, diff --git a/win32/Lib/pywin32_bootstrap.py b/win32/Lib/pywin32_bootstrap.py index c9f59a56d8..59c8f21d7c 100644 --- a/win32/Lib/pywin32_bootstrap.py +++ b/win32/Lib/pywin32_bootstrap.py @@ -7,7 +7,7 @@ try: - import pywin32_system32 + import pywin32_system32 # pyright: ignore[reportMissingImports] # Empty module created in setup.py to store dlls except ImportError: # Python ≥3.6: replace ImportError with ModuleNotFoundError pass else: diff --git a/win32/Lib/pywintypes.py b/win32/Lib/pywintypes.py index 36259df934..27543a9c4e 100644 --- a/win32/Lib/pywintypes.py +++ b/win32/Lib/pywintypes.py @@ -47,7 +47,7 @@ def __import_pywin32_system_module__(modname, globs): raise ImportError(f"Module '{modname}' isn't in frozen sys.path {sys.path}") else: # First see if it already in our process - if so, we must use that. - import _win32sysloader + import _win32sysloader # pyright: ignore[reportMissingImports] # Private c-extension module found = _win32sysloader.GetModuleFilename(filename) if found is None: @@ -93,7 +93,7 @@ def __import_pywin32_system_module__(modname, globs): # Simply import pywin32_system32 and look in the paths in pywin32_system32.__path__ if found is None: - import pywin32_system32 + import pywin32_system32 # pyright: ignore[reportMissingImports] # Empty module created in setup.py to store dlls for path in pywin32_system32.__path__: maybe = os.path.join(path, filename) diff --git a/win32/Lib/winxptheme.py b/win32/Lib/winxptheme.py index 4fd7ed9626..72c9873092 100644 --- a/win32/Lib/winxptheme.py +++ b/win32/Lib/winxptheme.py @@ -5,4 +5,4 @@ around _winxptheme. """ -from _winxptheme import * # nopycln: import +from _winxptheme import * # nopycln: import # pyright: ignore[reportMissingImports] # Private c-extension module diff --git a/win32/test/test_win32crypt.py b/win32/test/test_win32crypt.py index 9360cfbe22..15841e1ed3 100644 --- a/win32/test/test_win32crypt.py +++ b/win32/test/test_win32crypt.py @@ -1,4 +1,5 @@ # Test module for win32crypt +from __future__ import annotations import contextlib import unittest