Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/mhammond/pywin32 into adodb…
Browse files Browse the repository at this point in the history
…api-Update-collections-literals-and-comprehensions
  • Loading branch information
Avasam committed Apr 12, 2024
2 parents a699f47 + dde12b8 commit a2b7a44
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 107 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ max_line_length = 88 # Same as Black
[*.md]
trim_trailing_whitespace = false

[*.{yaml,yml,toml}]
[*.{yaml,yml,json,toml}]
indent_size = 2
10 changes: 6 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ jobs:
with:
# This job only needs to target the oldest supported version (black@stable supports Python >=3.8)
python-version: '3.8'
- run: pip install isort pycln
- run: pip install pycln
- run: pycln . --config=pycln.toml --check
- run: isort . --diff --check-only
- uses: chartboost/ruff-action@v1
with:
version: '0.3.4'
- uses: psf/black@stable
with:
options: "--fast --check --diff --verbose"
Expand All @@ -116,14 +118,14 @@ jobs:
strategy:
fail-fast: false
matrix:
# mypy 1.5 dropped support for python 3.7
# mypy 1.5 dropped support for Python 3.7
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: pip install types-regex types-setuptools mypy>=1.5
- run: pip install types-regex types-setuptools mypy==1.9
- run: mypy . --python-version=${{ matrix.python-version }}

pyright:
Expand Down
7 changes: 0 additions & 7 deletions .isort.cfg

This file was deleted.

9 changes: 4 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ repos:
- id: pycln
args: [--config=pycln.toml]
verbose: true
- repo: https://github.com/pycqa/isort
rev: 5.13.2
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
hooks:
- id: isort
name: isort (python)
verbose: true
- id: ruff # Run the linter.
args: [--fix]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.2.0
hooks:
Expand Down
8 changes: 6 additions & 2 deletions Pythonwin/pywin/scintilla/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
import win32ui
from pywin.mfc import afxres, docview

from . import IDLEenvironment # IDLE emulation.
from . import bindings, control, scintillacon
from . import (
IDLEenvironment, # IDLE emulation.
bindings,
control,
scintillacon,
)

PRINTDLGORD = 1538
IDC_PRINT_MAG_EDIT = 1010
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import win32api

# flag if we are in a "frozen" build.
_frozen = getattr(sys, "frozen", 1 == 0)
_frozen = getattr(sys, "frozen", False)
# pythoncom dumbly defaults this to zero - we believe sys.frozen over it.
if _frozen and not getattr(pythoncom, "frozen", 0):
pythoncom.frozen = sys.frozen
Expand Down
9 changes: 4 additions & 5 deletions com/win32com/client/connect.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Utilities for working with Connections"""

import pythoncom
import win32com.server.policy
import win32com.server.util


Expand All @@ -22,11 +23,9 @@ def __del__(self):
pass

def _wrap(self, obj):
useDispatcher = None
if self.debug:
from win32com.server import dispatcher

useDispatcher = dispatcher.DefaultDebugDispatcher
useDispatcher = (
win32com.server.policy.DispatcherWin32trace if self.debug else None
)
return win32com.server.util.wrap(obj, useDispatcher=useDispatcher)

def Connect(self, coInstance, eventInstance, eventCLSID=None):
Expand Down
22 changes: 4 additions & 18 deletions com/win32comext/axdebug/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys

import win32api
import win32com.server.policy
import win32com.server.util
import winerror
from win32com.server.exception import COMException
Expand Down Expand Up @@ -35,21 +36,9 @@ def trace(*args):
# now does ensure this.


def _wrap_nodebug(object, iid):
return win32com.server.util.wrap(object, iid)


def _wrap_debug(object, iid):
import win32com.server.policy

dispatcher = win32com.server.policy.DispatcherWin32trace
return win32com.server.util.wrap(object, iid, useDispatcher=dispatcher)


if debugging:
_wrap = _wrap_debug
else:
_wrap = _wrap_nodebug
def _wrap(object, iid):
useDispatcher = win32com.server.policy.DispatcherWin32trace if debugging else None
return win32com.server.util.wrap(object, iid, useDispatcher=useDispatcher)


def RaiseNotImpl(who=None):
Expand All @@ -69,9 +58,6 @@ def RaiseNotImpl(who=None):
raise COMException(scode=winerror.E_NOTIMPL)


import win32com.server.policy


class Dispatcher(win32com.server.policy.DispatcherWin32trace):
def __init__(self, policyClass, object):
win32com.server.policy.DispatcherTrace.__init__(self, policyClass, object)
Expand Down
17 changes: 3 additions & 14 deletions com/win32comext/axscript/client/scriptdispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,12 @@ def _getdispid_(self, name, fdex):
return win32com.server.policy.DynamicPolicy._getdispid_(self, name, fdex)


def _wrap_debug(obj):
def _wrap(obj):
useDispatcher = win32com.server.policy.DispatcherWin32trace if debugging else None
return win32com.server.util.wrap(
obj,
usePolicy=StrictDynamicPolicy,
useDispatcher=win32com.server.policy.DispatcherWin32trace,
obj, usePolicy=StrictDynamicPolicy, useDispatcher=useDispatcher
)


def _wrap_nodebug(obj):
return win32com.server.util.wrap(obj, usePolicy=StrictDynamicPolicy)


if debugging:
_wrap = _wrap_debug
else:
_wrap = _wrap_nodebug


def MakeScriptDispatch(engine, namespace):
return _wrap(ScriptDispatch(engine, namespace))
61 changes: 43 additions & 18 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,33 +1,53 @@
[mypy]
show_column_numbers = true
warn_unused_ignores = true
; Target the oldest supported version in editors
python_version = 3.7
; Target the oldest supported version in editors and default CLI
; mypy 1.5 dropped support for Python 3.7
python_version = 3.8

strict = false
strict = true
implicit_reexport = true
; Necessary to avoid "same module name" issues
explicit_package_bases = true
; Must specify top-level packages and scripts folders for mypy to work with explicit_package_bases
mypy_path =
$MYPY_CONFIG_FILE_DIR/com,
$MYPY_CONFIG_FILE_DIR/win32/Lib,
$MYPY_CONFIG_FILE_DIR/Pythonwin,
$MYPY_CONFIG_FILE_DIR/AutoDuck,
$MYPY_CONFIG_FILE_DIR/win32/scripts/VersionStamp,

; Implicit return types !
; TODO: turn back check_untyped_defs to true. For now this allows us to
; at least put mypy in place by massively reducing checked code
; TODO: Gradually type classes and functions until we can turn back check_untyped_defs to true.
; For now this allows us to at least put mypy in place by massively reducing checked code
check_untyped_defs = false
; Implicit return types !
disallow_untyped_calls = false
disallow_untyped_defs = false
disallow_incomplete_defs = false

; attr-defined: Module has no attribute (modules are dynamic)
; method-assign: Cannot assign to a method (lots of monkey patching)
; name-defined: Name "..." is not defined (dynamic modules will be hard to type without stubs, ie: pythoncom.*, leave undefined/unbound to Flake8/Ruff/pyright)
disable_error_code = attr-defined, method-assign, name-defined
; TODO: adodbapi should be updated and fixed separatly
; Pythonwin/Scintilla is vendored
; Pythonwin/pywin/idle is vendored IDLE extensions predating Python 2.3. They now live in idlelib in https://github.com/python/cpython/tree/main/Lib/idlelib
; Ignoring non-public apis for now
; Duplicate module named "rasutil" and "setup", short-term fix is to ignore
exclude = .*((build|adodbapi|Pythonwin/Scintilla|Pythonwin/pywin/idle|[Tt]est|[Dd]emos?)/.*|rasutil.py|setup.py)
disable_error_code =
; Module has no attribute; (Dynamic modules will be hard to type without first-party stubs, ie: pythoncom.*)
attr-defined,
; Class cannot subclass "..." (has type "Any"); (IDEM)
; TODO: Use typeshed's types-pywin32 stubs after a few more fixes there
misc,
; Name "..." is not defined; (IDEM, leave undefined/unbound to Flake8/Ruff/pyright)
name-defined,
; Cannot assign to a method (we do lots of monkey patching)
method-assign,
exclude = (?x)(
^build/
; Vendored
| ^Pythonwin/Scintilla/
; Forked IDLE extensions predating Python 2.3. They now live in idlelib in https://github.com/python/cpython/tree/main/Lib/idlelib
| ^Pythonwin/pywin/idle/
; TODO: adodbapi should be updated and fixed separatly
| ^adodbapi/
; TODO: Ignoring non-public APIs until all public API is typed
| ([Tt]est|[Dd]emos?)/
)

; C-modules that will need type-stubs
[mypy-adsi.*,dde,exchange,exchdapi,perfmon,servicemanager,win32api,win32console,win32clipboard,win32event,win32evtlog,win32file,win32gui,win32help,win32pdh,win32process,win32ras,win32security,win32service,win32trace,win32ui,win32uiole,win32wnet,_win32sysloader,_winxptheme]
[mypy-adsi.*,dde,exchange,exchdapi,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]
ignore_missing_imports = True

; verstamp is installed from win32verstamp.py called in setup.py
Expand All @@ -36,3 +56,8 @@ ignore_missing_imports = True
; pywin32_system32 is an empty module created in setup.py to store dlls
[mypy-verstamp,win32com.*,Test,pywin32_system32]
ignore_missing_imports = True

; Distutils being removed from stdlib currently causes some issues on Python 3.12
; https://github.com/mhammond/pywin32/issues/2119
[mypy-distutils.*]
ignore_missing_imports = True
8 changes: 4 additions & 4 deletions pyrightconfig.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"typeCheckingMode": "basic",
// Target the oldest supported version in editors
// Target the oldest supported version in editors and default CLI
"pythonVersion": "3.7",
// Keep it simple for now by allowing both mypy and pyright to use `type: ignore`
"enableTypeIgnoreComments": true,
// Exclude from scanning when running pyright
"exclude": [
"build/",
// TODO: adodbapi should be updated and fixed separatly
"adodbapi/",
// Vendored
"Pythonwin/Scintilla/",
// Vendored IDLE extensions predating Python 2.3. They now live in idlelib in https://github.com/python/cpython/tree/main/Lib/idlelib
// Forked IDLE extensions predating Python 2.3. They now live in idlelib in https://github.com/python/cpython/tree/main/Lib/idlelib
"Pythonwin/pywin/idle/",
// Ignoring non-public apis for now
"**/Test/",
"**/test/",
"**/Demos/",
"**/demo/",
// TODO: adodbapi should be updated and fixed separately
"adodbapi/",
],
// Packages that will be accessible globally.
// Setting this makes pyright use the repo's code for those modules instead of typeshed or pywin32 in site-packages
Expand Down
4 changes: 1 addition & 3 deletions pywin32_postinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,7 @@ 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( # pyright: ignore[reportOptionalMemberAccess] # We provide the loader, we know it won't be None
mod
)
loader.exec_module(mod)


def SetPyKeyVal(key_name, value_name, value):
Expand Down
18 changes: 18 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
target-version = "py37"

[lint]
select = ["I"]

[lint.isort]
combine-as-imports = true
# Because pywin32 has a mix of relative and absolute imports, with undetectable first-party c-extensions
# This makes import grouping more consistent
detect-same-package = false
known-third-party = [
"__main__",
# This forces distutils imports to always be after setuptools
# setuptools must be imported before distutils because it monkey-patches it.
# distutils is also removed in Python 3.12 and deprecated with setuptools
"distutils",
]
extra-standard-library = ["setuptools"]
Loading

0 comments on commit a2b7a44

Please sign in to comment.