Skip to content

Commit

Permalink
Resolve all pyright reportMissingImports
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Oct 23, 2024
1 parent 5a46a21 commit 49452f6
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion com/win32com/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down
16 changes: 13 additions & 3 deletions com/win32comext/adsi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import TYPE_CHECKING

import win32com
import win32com.client

Expand All @@ -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:
Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion com/win32comext/axdebug/codecontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
14 changes: 12 additions & 2 deletions com/win32comext/mapi/__init__.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
5 changes: 2 additions & 3 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pyrightconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"enableTypeIgnoreComments": true,
// Exclude from scanning when running pyright
"exclude": [
".git/",
"build/",
// Vendored
"Pythonwin/Scintilla/",
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 49452f6

Please sign in to comment.