diff --git a/com/win32com/__init__.py b/com/win32com/__init__.py index 3e42dcc10..d4747629b 100644 --- a/com/win32com/__init__.py +++ b/com/win32com/__init__.py @@ -98,7 +98,7 @@ def __PackageSupportBuildPath__(package_path): # a package. if not __gen_path__: try: - import win32com.gen_py + import win32com.gen_py # type: ignore[import-untyped] # TODO: Add to typeshed # __path__ is only ensured to be an Iterable, not a list. __gen_path__ = next(iter(sys.modules["win32com.gen_py"].__path__)) diff --git a/com/win32comext/adsi/__init__.py b/com/win32comext/adsi/__init__.py index 16afd3b78..238a1b976 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 * # 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 e7502845d..9da978eee 100644 --- a/com/win32comext/axdebug/codecontainer.py +++ b/com/win32comext/axdebug/codecontainer.py @@ -256,7 +256,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 # type: ignore[import-untyped] 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 181ae1c5c..261abecf2 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 e4676e0c7..9341c55b5 100644 --- a/mypy.ini +++ b/mypy.ini @@ -44,13 +44,12 @@ 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 ; Test is a local untyped module in win32comext.axdebug ; pywin32_system32 is an empty module created in setup.py to store dlls -[mypy-win32com.*,Test,pywin32_system32] +[mypy-Test,pywin32_system32] ignore_missing_imports = True ; Distutils being removed from stdlib currently causes some issues on Python 3.12 diff --git a/pyrightconfig.json b/pyrightconfig.json index d96b3fc9d..00f5528d0 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -6,6 +6,7 @@ "enableTypeIgnoreComments": true, // Exclude from scanning when running pyright "exclude": [ + ".git/", "build/", // Vendored "Pythonwin/Scintilla/", @@ -41,8 +42,6 @@ "reportUnnecessaryComparison": "warning", // TODO: Leave Unbound its own PR(s) "reportUnboundVariable": "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,