Skip to content

Commit

Permalink
Remove trailing whitespaces not handled by black
Browse files Browse the repository at this point in the history
And use ruff to prevent regressions
  • Loading branch information
Avasam committed Mar 24, 2024
1 parent 7cac4eb commit a30642c
Show file tree
Hide file tree
Showing 19 changed files with 81 additions and 72 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ jobs:
- run: pip install isort 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 Down
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ repos:
- id: isort
name: isort (python)
verbose: true
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
hooks:
- id: ruff # Run the linter.
args: [--fix]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.2.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/dialogs/login.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""login -- PythonWin user ID and password dialog box
(Adapted from originally distributed with Mark Hammond's PythonWin -
(Adapted from originally distributed with Mark Hammond's PythonWin -
this now replaces it!)
login.GetLogin() displays a modal "OK/Cancel" dialog box with input
Expand Down
2 changes: 1 addition & 1 deletion adodbapi/test/adodbapitestconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
--mssql - test against Microsoft SQL server
--pg - test against PostgreSQL
--mysql - test against MariaDB
--remote= - test unsing remote server at= (experimental)
--remote= - test unsing remote server at= (experimental)
"""
)
exit()
Expand Down
4 changes: 2 additions & 2 deletions adodbapi/test/dbapi20.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
""" Python DB API 2.0 driver compliance unit test suite.
""" Python DB API 2.0 driver compliance unit test suite.
This software is Public Domain and may be used without restrictions.
"Now we have booze and barflies entering the discussion, plus rumours of
Expand Down
11 changes: 5 additions & 6 deletions com/win32com/makegw/makegw.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
This module will generate a C++/Python binding for a specific COM
interface.
Can be run from command line (passing required arguments) or the old way
(start Python, import this module, change to the directory where the generated code
should be written, and run the public function).
This module is capable of generating both 'Interfaces' (ie, Python
client side support for the interface) and 'Gateways' (ie, Python
server side support for the interface). Many COM interfaces are useful
both as Client and Server. Other interfaces, however, really only make
sense to implement one side or the other. For example, it would be pointless
for Python to implement Server side for 'IRunningObjectTable', unless we were
implementing core COM for an operating system in Python (hey - now there's an idea!)
Most COM interface code is totally boiler-plate - it consists of
converting arguments, dispatching the call to Python, and processing
any result values.
This module automates the generation of such code. It has the ability to
parse a .H file generated by the MIDL tool (ie, almost all COM .h files)
and build almost totally complete C++ code.
The module understands some of the well known data types, and how to
convert them. There are only a couple of places where hand-editing is
necessary, as detailed below:
Expand All @@ -43,7 +43,6 @@
* FAILED(scode) for the interface still has valid data to return (by default,
the code generated does not process the return values, and raise an exception
to Python/COM
"""

import argparse
Expand Down
6 changes: 3 additions & 3 deletions com/win32com/makegw/makegwenum.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def _write_enumgw_cpp(f, interface):
STDMETHODIMP PyGEnum{enumtype}::GetIDsOfNames(REFIID refiid, OLECHAR FAR* FAR* rgszNames, UINT cNames, LCID lcid, DISPID FAR* rgdispid) {{return PyGatewayBase::GetIDsOfNames( refiid, rgszNames, cNames, lcid, rgdispid);}}
STDMETHODIMP PyGEnum{enumtype}::Invoke(DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR* params, VARIANT FAR* pVarResult, EXCEPINFO FAR* pexcepinfo, UINT FAR* puArgErr) {{return PyGatewayBase::Invoke( dispid, riid, lcid, wFlags, params, pVarResult, pexcepinfo, puArgErr);}}
STDMETHODIMP PyGEnum{enumtype}::Next(
STDMETHODIMP PyGEnum{enumtype}::Next(
/* [in] */ ULONG celt,
/* [length_is][size_is][out] */ {argdeclare},
/* [out] */ ULONG __RPC_FAR *pCeltFetched)
Expand Down Expand Up @@ -273,7 +273,7 @@ def _write_enumgw_cpp(f, interface):
return PyCom_HandleIEnumNoSequence(IID_IEnum{enumtype});
}}
STDMETHODIMP PyGEnum{enumtype}::Skip(
STDMETHODIMP PyGEnum{enumtype}::Skip(
/* [in] */ ULONG celt)
{{
PY_GATEWAY_METHOD;
Expand All @@ -286,7 +286,7 @@ def _write_enumgw_cpp(f, interface):
return InvokeViaPolicy("Reset");
}}
STDMETHODIMP PyGEnum{enumtype}::Clone(
STDMETHODIMP PyGEnum{enumtype}::Clone(
/* [out] */ IEnum{enumtype} __RPC_FAR *__RPC_FAR *ppEnum)
{{
PY_GATEWAY_METHOD;
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/makegw/makegwparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Each argument knows how to use Py_BuildValue or Py_ParseTuple to
exchange itself with Python.
See the @win32com.makegw@ module for information in building a COM
interface
"""
Expand Down
5 changes: 2 additions & 3 deletions com/win32com/server/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
To better support COM exceptions, the framework allows for an instance to be
raised. This instance may have a certain number of known attributes, which are
translated into COM exception details.
This means, for example, that Python could raise a COM exception that includes details
on a Help file and location, and a description for the user.
This module provides a class which provides the necessary attributes.
This module provides a class which provides the necessary attributes.
"""

import sys
Expand Down
65 changes: 32 additions & 33 deletions com/win32com/server/policy.py
Original file line number Diff line number Diff line change
@@ -1,70 +1,69 @@
"""Policies
"""Policies
Note that Dispatchers are now implemented in "dispatcher.py", but
are still documented here.
Policies
A policy is an object which manages the interaction between a public
Python object, and COM . In simple terms, the policy object is the
object which is actually called by COM, and it invokes the requested
method, fetches/sets the requested property, etc. See the
A policy is an object which manages the interaction between a public
Python object, and COM . In simple terms, the policy object is the
object which is actually called by COM, and it invokes the requested
method, fetches/sets the requested property, etc. See the
@win32com.server.policy.CreateInstance@ method for a description of
how a policy is specified or created.
Exactly how a policy determines which underlying object method/property
is obtained is up to the policy. A few policies are provided, but you
can build your own. See each policy class for a description of how it
Exactly how a policy determines which underlying object method/property
is obtained is up to the policy. A few policies are provided, but you
can build your own. See each policy class for a description of how it
implements its policy.
There is a policy that allows the object to specify exactly which
methods and properties will be exposed. There is also a policy that
will dynamically expose all Python methods and properties - even those
There is a policy that allows the object to specify exactly which
methods and properties will be exposed. There is also a policy that
will dynamically expose all Python methods and properties - even those
added after the object has been instantiated.
Dispatchers
A Dispatcher is a level in front of a Policy. A dispatcher is the
thing which actually receives the COM calls, and passes them to the
policy object (which in turn somehow does something with the wrapped
A Dispatcher is a level in front of a Policy. A dispatcher is the
thing which actually receives the COM calls, and passes them to the
policy object (which in turn somehow does something with the wrapped
object).
It is important to note that a policy does not need to have a dispatcher.
A dispatcher has the same interface as a policy, and simply steps in its
place, delegating to the real policy. The primary use for a Dispatcher
is to support debugging when necessary, but without imposing overheads
A dispatcher has the same interface as a policy, and simply steps in its
place, delegating to the real policy. The primary use for a Dispatcher
is to support debugging when necessary, but without imposing overheads
when not (ie, by not using a dispatcher at all).
There are a few dispatchers provided - "tracing" dispatchers which simply
prints calls and args (including a variation which uses
win32api.OutputDebugString), and a "debugger" dispatcher, which can
There are a few dispatchers provided - "tracing" dispatchers which simply
prints calls and args (including a variation which uses
win32api.OutputDebugString), and a "debugger" dispatcher, which can
invoke the debugger when necessary.
Error Handling
It is important to realise that the caller of these interfaces may
not be Python. Therefore, general Python exceptions and tracebacks aren't
not be Python. Therefore, general Python exceptions and tracebacks aren't
much use.
In general, there is an COMException class that should be raised, to allow
In general, there is an COMException class that should be raised, to allow
the framework to extract rich COM type error information.
The general rule is that the **only** exception returned from Python COM
Server code should be an COMException instance. Any other Python exception
should be considered an implementation bug in the server (if not, it
should be handled, and an appropriate COMException instance raised). Any
other exception is considered "unexpected", and a dispatcher may take
The general rule is that the **only** exception returned from Python COM
Server code should be an COMException instance. Any other Python exception
should be considered an implementation bug in the server (if not, it
should be handled, and an appropriate COMException instance raised). Any
other exception is considered "unexpected", and a dispatcher may take
special action (see Dispatchers above)
Occasionally, the implementation will raise the policy.error error.
This usually means there is a problem in the implementation that the
Occasionally, the implementation will raise the policy.error error.
This usually means there is a problem in the implementation that the
Python programmer should fix.
For example, if policy is asked to wrap an object which it can not
support (because, eg, it does not provide _public_methods_ or _dynamic_)
then policy.error will be raised, indicating it is a Python programmers
For example, if policy is asked to wrap an object which it can not
support (because, eg, it does not provide _public_methods_ or _dynamic_)
then policy.error will be raised, indicating it is a Python programmers
problem, rather than a COM error.
"""

__author__ = "Greg Stein and Mark Hammond"
Expand Down
3 changes: 1 addition & 2 deletions com/win32com/server/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
""" General Server side utilities
"""
""" General Server side utilities"""

import pythoncom
import winerror
Expand Down
7 changes: 3 additions & 4 deletions com/win32com/test/testGIT.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Testing pasing object between multiple COM threads
Uses standard COM marshalling to pass objects between threads. Even
Uses standard COM marshalling to pass objects between threads. Even
though Python generally seems to work when you just pass COM objects
between threads, it shouldnt.
Expand All @@ -10,15 +10,14 @@
COM marshalls back all calls to that object to the main Python thread,
which must be running a message loop (as this sample does).
When this test is run in "free threaded" mode (at this stage, you must
manually mark the COM objects as "ThreadingModel=Free", or run from a
When this test is run in "free threaded" mode (at this stage, you must
manually mark the COM objects as "ThreadingModel=Free", or run from a
service which has marked itself as free-threaded), then no marshalling
is done, and the Python.Interpreter object start doing the "expected" thing
- ie, it reports being on the same thread as its caller!
Python.exe needs a good way to mark itself as FreeThreaded - at the moment
this is a pain in the but!
"""

import _thread
Expand Down
2 changes: 1 addition & 1 deletion com/win32comext/axscript/server/error.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Exception instance for AXScript servers.
This module implements an exception instance that is raised by the core
This module implements an exception instance that is raised by the core
server scripting support.
When a script error occurs, it wraps the COM object that describes the
Expand Down
4 changes: 2 additions & 2 deletions com/win32comext/axscript/test/testHost.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def NotifyDoneIt(self, interface, arg):
sub hello(arg1)
test.echo arg1
end sub
sub testcollection
if test.collection.Item(0) <> 1 then
test.fail("Index 0 was wrong")
Expand All @@ -122,7 +122,7 @@ def NotifyDoneIt(self, interface, arg):
prop = "Property Value"
def hello(arg1):
test.echo(arg1)
def testcollection():
# test.collection[1] = "New one"
got = []
Expand Down
2 changes: 1 addition & 1 deletion com/win32comext/shell/demos/explorer_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from win32com.shell import shell, shellcon

# event handler for the browser.
IExplorerBrowserEvents_Methods = """OnNavigationComplete OnNavigationFailed
IExplorerBrowserEvents_Methods = """OnNavigationComplete OnNavigationFailed
OnNavigationPending OnViewCreated""".split()


Expand Down
7 changes: 7 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Target the oldest supported version
target-version = "py37"

[lint]
select = [
"W", # pycodestyle Warning
]
2 changes: 1 addition & 1 deletion win32/Demos/win32rcparser_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def DemoModal():

if __name__ == "__main__":
flags = 0
for flag in """ICC_DATE_CLASSES ICC_ANIMATE_CLASS ICC_ANIMATE_CLASS
for flag in """ICC_DATE_CLASSES ICC_ANIMATE_CLASS ICC_ANIMATE_CLASS
ICC_BAR_CLASSES ICC_COOL_CLASSES ICC_DATE_CLASSES
ICC_HOTKEY_CLASS ICC_INTERNET_CLASSES ICC_LISTVIEW_CLASSES
ICC_PAGESCROLLER_CLASS ICC_PROGRESS_CLASS ICC_TAB_CLASSES
Expand Down
19 changes: 9 additions & 10 deletions win32/Lib/win32pdhquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
The basic idea of a PDH Query is an object which can query the system
about the status of any number of "counters." The counters are paths
to a particular piece of performance data. For instance, the path
to a particular piece of performance data. For instance, the path
'\\Memory\\Available Bytes' describes just about exactly what it says
it does, the amount of free memory on the default computer expressed
in Bytes. These paths can be considerably more complex than this,
it does, the amount of free memory on the default computer expressed
in Bytes. These paths can be considerably more complex than this,
but part of the point of this wrapper module is to hide that
complexity from the end-user/programmer.
Expand All @@ -27,17 +27,17 @@
As an example, the following code implements a logger which allows the
user to choose what counters they would like to log, and logs those
counters for 30 seconds, at two-second intervals.
query = Query()
query.addcounterbybrowsing()
query.collectdatafor(30,2)
The data is now stored in a list of lists as:
query.curresults
The counters(paths) which were used to collect the data are:
query.curpaths
You can use the win32pdh.ParseCounterPath(path) utility function
to turn the paths into more easily read values for your task, or
write the data to a file, or do whatever you want with it.
Expand Down Expand Up @@ -79,7 +79,7 @@
workaround other than Alt-tabing to reach the browser window.
### Other References ###
The win32pdhutil module (which should be in the %pythonroot%/win32/lib
The win32pdhutil module (which should be in the %pythonroot%/win32/lib
directory) provides quick-and-dirty utilities for one-off access to
variables from the PDH. Almost everything in that module can be done
with a Query object, but it provides task-oriented functions for a
Expand All @@ -96,7 +96,7 @@
In general the Python version of the API is just a wrapper around the
Query-based version of this API (as far as I can see), so you can learn what
you need to from there. From what I understand, the MSDN Online
you need to from there. From what I understand, the MSDN Online
resources are available for the price of signing up for them. I can't
guarantee how long that's supposed to last. (Or anything for that
matter).
Expand All @@ -121,7 +121,6 @@
Use at your own risk, no warranties, no guarantees, no assurances,
if you use it, you accept the risk of using it, etceteras.
"""

# Feb 12, 98 - MH added "rawaddcounter" so caller can get exception details.
Expand Down
2 changes: 1 addition & 1 deletion win32/scripts/rasutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def Disconnect(handle):
Usage:
rasutil [-r retryCount] [-c rasname] [-d rasname]
-r retryCount - Number of times to retry the RAS connection
-c rasname - Connect to the phonebook entry specified by rasname
-d rasname - Disconnect from the phonebook entry specified by rasname
Expand Down

0 comments on commit a30642c

Please sign in to comment.