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

Use PyUpgrade to upgrade to Python 3.8 syntax #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions comtypes/_comobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _InterlockedDecrement(ob: c_long) -> int:
_PostQuitMessage.restype = None


class LocalServer(object):
class LocalServer:
_queue: Optional[queue.Queue] = None

def run(self, classobjects: Sequence["hints.localserver.ClassFactory"]) -> None:
Expand Down Expand Up @@ -182,7 +182,7 @@ def Unlock(self) -> None:
_PostQuitMessage(0)


class InprocServer(object):
class InprocServer:
def __init__(self) -> None:
self.locks = c_long(0)

Expand All @@ -203,7 +203,7 @@ def DllCanUnloadNow(self) -> int:
_T_IUnknown = TypeVar("_T_IUnknown", bound=IUnknown)


class COMObject(object):
class COMObject:
_com_interfaces_: ClassVar[List[Type[IUnknown]]]
_outgoing_interfaces_: ClassVar[List[Type["hints.IDispatch"]]]
_instances_: ClassVar[Dict["COMObject", None]] = {}
Expand All @@ -214,7 +214,7 @@ class COMObject(object):
_dispimpl_: Dict[Tuple[int, int], Callable[..., Any]]

def __new__(cls, *args, **kw):
self = super(COMObject, cls).__new__(cls)
self = super().__new__(cls)
if isinstance(self, c_void_p):
# We build the VTables only for direct instances of
# CoClass, not for POINTERs to CoClass.
Expand Down Expand Up @@ -410,7 +410,7 @@ def IProvideClassInfo_GetClassInfo(self) -> ITypeInfo:
try:
self.__typelib
except AttributeError:
raise WindowsError(hresult.E_NOTIMPL)
raise OSError(hresult.E_NOTIMPL)
return self.__typelib.GetTypeInfoOfGuid(self._reg_clsid_)

################################################################
Expand All @@ -419,7 +419,7 @@ def IProvideClassInfo_GetClassInfo(self) -> ITypeInfo:
def IProvideClassInfo2_GetGUID(self, dwGuidKind: int) -> GUID:
# GUIDKIND_DEFAULT_SOURCE_DISP_IID = 1
if dwGuidKind != 1:
raise WindowsError(hresult.E_INVALIDARG)
raise OSError(hresult.E_INVALIDARG)
return self._outgoing_interfaces_[0]._iid_

################################################################
Expand Down
14 changes: 7 additions & 7 deletions comtypes/_memberspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class helpstring(str):
"Specifies the helpstring for a COM method or property."


class defaultvalue(object):
class defaultvalue:
"Specifies the default value for parameters marked optional."

def __init__(self, value):
Expand Down Expand Up @@ -313,7 +313,7 @@ def prepare_parameter(v):
return call_with_inout


class PropertyMapping(object):
class PropertyMapping:
def __init__(self):
self._data: Dict[Tuple[str, _DocType, int], List[_PropFunc]] = {}

Expand Down Expand Up @@ -353,7 +353,7 @@ def put_or_putref(self, *args):
yield (name, doc, nargs, fget, fset)


class PropertyGenerator(object):
class PropertyGenerator:
def __init__(self, cls_name: str) -> None:
self._mapping = PropertyMapping()
self._cls_name = cls_name
Expand Down Expand Up @@ -431,7 +431,7 @@ def to_propputref_keys(self, m: _DispMemberSpec) -> Tuple[str, _DocType, int]:
return m.name, None, len(m.argspec) - 1


class ComMemberGenerator(object):
class ComMemberGenerator:
def __init__(self, cls_name: str, vtbl_offset: int, iid: "comtypes.GUID") -> None:
self._vtbl_offset = vtbl_offset
self._iid = iid
Expand Down Expand Up @@ -476,7 +476,7 @@ def properties(self):
return iter(self._props)


class DispMemberGenerator(object):
class DispMemberGenerator:
def __init__(self, cls_name: str) -> None:
self._props = DispPropertyGenerator(cls_name)
# sequence of (name: str, func_or_prop: Callable | property, is_prop: bool)
Expand Down Expand Up @@ -572,7 +572,7 @@ def properties(self):
# Should they be implemented in C for speed?


class bound_named_property(object):
class bound_named_property:
def __init__(self, name, fget, fset, instance):
self.name = name
self.instance = instance
Expand Down Expand Up @@ -613,7 +613,7 @@ def __iter__(self):
raise TypeError(msg)


class named_property(object):
class named_property:
def __init__(self, name, fget=None, fset=None, doc=None):
self.name = name
self.fget = fget
Expand Down
2 changes: 1 addition & 1 deletion comtypes/_npsupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def isndarray(self, value):
if hasattr(value, "__array_interface__"):
raise ValueError(
(
"Argument {0} appears to be a numpy.ndarray, but "
"Argument {} appears to be a numpy.ndarray, but "
"comtypes numpy support has not been enabled. Please "
"try calling comtypes.npsupport.enable_numpy_interop()"
" before passing ndarrays as parameters."
Expand Down
10 changes: 5 additions & 5 deletions comtypes/_post_coinit/_cominterface_meta_patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def case_insensitive(p: Type) -> None:
@patcher.Patch(p)
class CaseInsensitive(object):
class CaseInsensitive:
# case insensitive attributes for COM methods and properties
def __getattr__(self, name):
"""Implement case insensitive access to methods and properties"""
Expand All @@ -35,7 +35,7 @@ def __setattr__(self, name, value):

def reference_fix(pp: Type) -> None:
@patcher.Patch(pp)
class ReferenceFix(object):
class ReferenceFix:
def __setitem__(self, index, value):
# We override the __setitem__ method of the
# POINTER(POINTER(interface)) type, so that the COM
Expand Down Expand Up @@ -65,15 +65,15 @@ def __setitem__(self, index, value):

def sized(itf: Type) -> None:
@patcher.Patch(itf)
class _(object):
class _:
def __len__(self):
"Return the the 'self.Count' property."
return self.Count


def callable_and_subscriptable(itf: Type) -> None:
@patcher.Patch(itf)
class _(object):
class _:
# 'Item' is the 'default' value. Make it available by
# calling the instance (Not sure this makes sense, but
# win32com does this also).
Expand Down Expand Up @@ -128,7 +128,7 @@ def __setitem__(self, index, value):

def iterator(itf: Type) -> None:
@patcher.Patch(itf)
class _(object):
class _:
def __iter__(self):
"Return an iterator over the _NewEnum collection."
# This method returns a pointer to _some_ _NewEnum interface.
Expand Down
10 changes: 4 additions & 6 deletions comtypes/_post_coinit/unknwn.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _shutdown(
else:
try:
func()
except WindowsError:
except OSError:
pass
# Set the flag which means that calling obj.Release() is no longer
# needed.
Expand Down Expand Up @@ -283,14 +283,12 @@ def __eq__(self, other):
if not isinstance(other, _compointer_base):
return False
# get the value property of the c_void_p baseclass, this is the pointer value
return (
super(_compointer_base, self).value == super(_compointer_base, other).value
)
return super().value == super(_compointer_base, other).value

def __hash__(self):
"""Return the hash value of the pointer."""
# hash the pointer values
return hash(super(_compointer_base, self).value)
return hash(super().value)

# redefine the .value property; return the object itself.
def __get_value(self):
Expand All @@ -299,7 +297,7 @@ def __get_value(self):
value = property(__get_value, doc="""Return self.""")

def __repr__(self):
ptr = super(_compointer_base, self).value
ptr = super().value
return f"<{self.__class__.__name__} ptr=0x{ptr or 0:x} at {id(self):x}>"

# This fixes the problem when there are multiple python interface types
Expand Down
8 changes: 4 additions & 4 deletions comtypes/_vtbl.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def call_with_this(*args, **kw):
except comtypes.ReturnHRESULT as err:
(hr, text) = err.args
return ReportError(text, iid=interface._iid_, clsid=clsid, hresult=hr)
except (COMError, WindowsError) as details:
except (COMError, OSError) as details:
_error(
"Exception in %s.%s implementation:",
interface.__name__,
Expand Down Expand Up @@ -204,7 +204,7 @@ def call_without_this(this, *args):
msg = f"{source}: {descr}"
hr = HRESULT_FROM_WIN32(hr)
return ReportError(msg, iid=interface._iid_, clsid=clsid, hresult=hr)
except WindowsError as details:
except OSError as details:
_error(
"Exception in %s.%s implementation:",
interface.__name__,
Expand All @@ -231,11 +231,11 @@ def call_without_this(this, *args):
return call_without_this


class _MethodFinder(object):
class _MethodFinder:
def __init__(self, inst: "hints.COMObject") -> None:
self.inst = inst
# map lower case names to names with correct spelling.
self.names = dict([(n.lower(), n) for n in dir(inst)])
self.names = {n.lower(): n for n in dir(inst)}

def get_impl(
self,
Expand Down
2 changes: 1 addition & 1 deletion comtypes/automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ def ChangeType(self, typecode):


@comtypes.patcher.Patch(POINTER(VARIANT))
class _(object):
class _:
# Override the default .from_param classmethod of POINTER(VARIANT).
# This allows to pass values which can be stored in VARIANTs as
# function parameters declared as POINTER(VARIANT). See
Expand Down
2 changes: 1 addition & 1 deletion comtypes/client/_code_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _create_comtypes_gen_package():
ofi = open(comtypes_init, "w")
ofi.write("# comtypes.gen package, directory for generated files.\n")
ofi.close()
except (OSError, IOError) as details:
except OSError as details:
logger.info("Creating comtypes.gen package failed: %s", details)
module = sys.modules["comtypes.gen"] = types.ModuleType("comtypes.gen")
comtypes.gen = module
Expand Down
2 changes: 1 addition & 1 deletion comtypes/client/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def setdefault(self, key, default=None):
raise TypeError


class Constants(object):
class Constants:
"""This class loads the type library from the supplied object,
then exposes constants and enumerations in the type library
as attributes.
Expand Down
12 changes: 6 additions & 6 deletions comtypes/client/_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SECURITY_ATTRIBUTES(Structure):
_CloseHandle.restype = BOOL


class _AdviseConnection(object):
class _AdviseConnection:
def __init__(self, source, interface, receiver):
self.cp = None
self.cookie = None
Expand All @@ -83,7 +83,7 @@ def __del__(self):
try:
if self.cookie is not None:
self.cp.Unadvise(self.cookie)
except (comtypes.COMError, WindowsError):
except (comtypes.COMError, OSError):
# Are we sure we want to ignore errors here?
pass

Expand Down Expand Up @@ -187,7 +187,7 @@ class _SinkMethodFinder(_MethodFinder):
"""

def __init__(self, inst, sink):
super(_SinkMethodFinder, self).__init__(inst)
super().__init__(inst)
self.sink = sink

def find_method(self, fq_name, mthname):
Expand All @@ -207,7 +207,7 @@ def find_method(self, fq_name, mthname):

def _find_method(self, fq_name, mthname):
try:
return super(_SinkMethodFinder, self).find_method(fq_name, mthname)
return super().find_method(fq_name, mthname)
except AttributeError:
try:
return getattr(self.sink, fq_name)
Expand Down Expand Up @@ -261,7 +261,7 @@ def GetEvents(source, sink, interface=None):
return _AdviseConnection(source, interface, rcv)


class EventDumper(object):
class EventDumper:
"""Universal sink for COM events."""

def __getattr__(self, name):
Expand Down Expand Up @@ -342,7 +342,7 @@ def HandlerRoutine(dwCtrlType):
handles,
ctypes.byref(ctypes.c_ulong()),
)
except WindowsError as details:
except OSError as details:
if details.winerror != RPC_S_CALLPENDING: # timeout expired
raise
else:
Expand Down
2 changes: 1 addition & 1 deletion comtypes/client/_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def _create_module(modulename: str, code: str) -> types.ModuleType:
return _my_import(modulename)


class ModuleGenerator(object):
class ModuleGenerator:
def __init__(self, tlib: typeinfo.ITypeLib, pathname: Optional[str]) -> None:
self.wrapper_name = codegenerator.name_wrapper_module(tlib)
self.friendly_name = codegenerator.name_friendly_module(tlib)
Expand Down
6 changes: 3 additions & 3 deletions comtypes/client/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def Dispatch(obj):
if isinstance(obj, ctypes.POINTER(automation.IDispatch)):
try:
tinfo = obj.GetTypeInfo(0)
except (COMError, WindowsError):
except (COMError, OSError):
return _Dispatch(obj)
return lazybind.Dispatch(obj, tinfo)
return obj
Expand Down Expand Up @@ -60,7 +60,7 @@ def __setitem__(self, *args: Any) -> None:
)


class _Dispatch(object):
class _Dispatch:
"""Expose methods and properties via fully dynamic dispatch."""

_comobj: automation.IDispatch
Expand Down Expand Up @@ -161,7 +161,7 @@ def __iter__(self) -> "_Collection":
# )


class _Collection(object):
class _Collection:
def __init__(self, enum: automation.IEnumVARIANT):
self.enum = enum

Expand Down
6 changes: 3 additions & 3 deletions comtypes/client/lazybind.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from comtypes.typeinfo import FUNC_PUREVIRTUAL, FUNC_DISPATCH


class FuncDesc(object):
class FuncDesc:
"""Stores important FUNCDESC properties by copying them from a
real FUNCDESC instance.
"""
Expand All @@ -29,7 +29,7 @@ def __init__(self, **kw):
_all_slice = slice(None, None, None)


class NamedProperty(object):
class NamedProperty:
def __init__(self, disp, get, put, putref):
self.get = get
self.put = put
Expand Down Expand Up @@ -84,7 +84,7 @@ def __iter__(self):
# objects do not (could be added, would probably be expensive)


class Dispatch(object):
class Dispatch:
"""Dynamic dispatch for an object the exposes type information.
Binding at runtime is done via ITypeComp::Bind calls.
"""
Expand Down
2 changes: 1 addition & 1 deletion comtypes/errorinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def ReportError(
clsid = GUID(clsid)
try:
progid = clsid.as_progid()
except WindowsError:
except OSError:
pass
else:
ei.SetSource(
Expand Down
2 changes: 1 addition & 1 deletion comtypes/hresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def MAKE_HRESULT(sev, fac, code):
# A hresult is SIGNED in comtypes
from ctypes import c_long

return c_long((sev << 31 | fac << 16 | code)).value
return c_long(sev << 31 | fac << 16 | code).value


SEVERITY_ERROR = 1
Expand Down
Loading