Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve all pyright reportMissingImports #2420

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
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 * # nopycln: 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 @@ -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])
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
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions pyrightconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion win32/Lib/pywin32_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions win32/Lib/pywintypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion win32/Lib/winxptheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
around _winxptheme.
"""

from _winxptheme import * # nopycln: import
from _winxptheme import * # nopycln: import # pyright: ignore[reportMissingImports] # Private c-extension module
1 change: 1 addition & 0 deletions win32/test/test_win32crypt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Test module for win32crypt
from __future__ import annotations

import contextlib
import unittest
Expand Down