Skip to content

Commit

Permalink
Merge branch 'main' into fix_525_attempted_to_reuse_key_and_more
Browse files Browse the repository at this point in the history
  • Loading branch information
junkmd committed Sep 29, 2024
2 parents 7b3caab + 8613f03 commit 3795c56
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
9 changes: 5 additions & 4 deletions comtypes/client/_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def GetModule(tlib: _UnionT[Any, typeinfo.ITypeLib]) -> types.ModuleType:
frame = sys._getframe(1)
_file_: Optional[str] = frame.f_globals.get("__file__", None)
pathname, is_abs = _resolve_filename(
tlib_string, _file_ and os.path.dirname(_file_) # type: ignore
tlib_string,
_file_ and os.path.dirname(_file_), # type: ignore
)
logger.debug("GetModule(%s), resolved: %s", pathname, is_abs)
tlib = _load_tlib(pathname) # don't register
Expand Down Expand Up @@ -251,9 +252,9 @@ def generate(self) -> types.ModuleType:
_ItfIid = str


def _get_known_namespaces() -> Tuple[
Mapping[_SymbolName, _ModuleName], Mapping[_ItfName, _ItfIid]
]:
def _get_known_namespaces() -> (
Tuple[Mapping[_SymbolName, _ModuleName], Mapping[_ItfName, _ItfIid]]
):
"""Returns symbols and interfaces that are already statically defined in `ctypes`
and `comtypes`.
From `ctypes`, all the names are obtained.
Expand Down
4 changes: 1 addition & 3 deletions comtypes/safearray.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,7 @@ def create_from_ndarray(cls, value, extra, lBound=0):
nitems *= d
rgsa[i].cElements = d
rgsa[i].lBound = lBound
pa = _safearray.SafeArrayCreateEx(
cls._vartype_, value.ndim, rgsa, extra # cDims # rgsaBound
) # pvExtra
pa = _safearray.SafeArrayCreateEx(cls._vartype_, value.ndim, rgsa, extra)
if not pa:
if cls._vartype_ == VT_RECORD and extra is None:
raise TypeError(
Expand Down
2 changes: 1 addition & 1 deletion comtypes/test/test_inout_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def test_permutations(self):
(orig_0th, *orig_call_args), orig_kw = orig.call_args
self.assertEqual(orig_kw, {})
self.assertIs(orig_0th, self_)
for ((typ, f, val), orig) in zip(
for (typ, f, val), orig in zip(
testing_params.call_args_validators, orig_call_args
):
self.assertIsInstance(orig, typ)
Expand Down
12 changes: 6 additions & 6 deletions comtypes/tools/codegenerator/namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ def get_symbols(self) -> Set[str]:

def _make_line(self, from_: str, imports: Sequence[str]) -> str:
import_ = ", ".join(imports)
code = "from %s import %s" % (from_, import_)
code = f"from {from_} import {import_}"
if len(code) <= 80:
return code
wrapper = textwrap.TextWrapper(
subsequent_indent=" ", initial_indent=" ", break_long_words=False
)
import_ = "\n".join(wrapper.wrap(import_))
code = "from %s import (\n%s\n)" % (from_, import_)
code = f"from {from_} import (\n{import_}\n)"
return code

def getvalue(self) -> str:
Expand All @@ -105,12 +105,12 @@ def getvalue(self) -> str:
if val is None:
ns[key] = val
elif key == "*":
lines.append("from %s import *" % val)
lines.append(f"from {val} import *")
else:
ns.setdefault(val, set()).add(key) # type: ignore
for key, val in ns.items():
if val is None:
lines.append("import %s" % key)
lines.append(f"import {key}")
else:
names = sorted(val, key=lambda s: s.lower())
lines.append(self._make_line(key, names))
Expand Down Expand Up @@ -146,9 +146,9 @@ def get_symbols(self) -> Set[str]:
def getvalue(self) -> str:
lines = []
for (alias, definition), comment in self.data.items():
code = "%s = %s" % (alias, definition)
code = f"{alias} = {definition}"
if comment:
code = code + " # %s" % comment
code = code + f" # {comment}"
lines.append(code)
return "\n".join(lines)

Expand Down
2 changes: 1 addition & 1 deletion comtypes/tools/tlbparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ def get_tlib_filename(tlib: typeinfo.ITypeLib) -> Optional[str]:
la = tlib.GetLibAttr()
name = BSTR()
if 0 == windll.oleaut32.QueryPathOfRegTypeLib(
byref(la.guid), la.wMajorVerNum, la.wMinorVerNum, 0, byref(name) # lcid
byref(la.guid), la.wMajorVerNum, la.wMinorVerNum, 0, byref(name)
):
full_filename = name.value.split("\0")[0]
if not os.path.isabs(full_filename):
Expand Down
12 changes: 8 additions & 4 deletions comtypes/typeinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ def ReleaseTLibAttr(self, ptla: "_Pointer[TLIBATTR]") -> int:
def GetLibAttr(self) -> "TLIBATTR":
"""Return type library attributes"""
return _deref_with_release(
self._GetLibAttr(), self.ReleaseTLibAttr # type: ignore
self._GetLibAttr(), # type: ignore
self.ReleaseTLibAttr,
)

def IsName(self, name: str, lHashVal: int = 0) -> Optional[str]:
Expand Down Expand Up @@ -345,7 +346,8 @@ def ReleaseVarDesc(self, pVarDesc: "_Pointer[VARDESC]") -> int:
def GetTypeAttr(self) -> "TYPEATTR":
"""Return the TYPEATTR for this type"""
return _deref_with_release(
self._GetTypeAttr(), self.ReleaseTypeAttr # type: ignore
self._GetTypeAttr(), # type: ignore
self.ReleaseTypeAttr,
)

def GetDocumentation(
Expand All @@ -358,13 +360,15 @@ def GetDocumentation(
def GetFuncDesc(self, index: int) -> "FUNCDESC":
"""Return FUNCDESC for index"""
return _deref_with_release(
self._GetFuncDesc(index), self.ReleaseFuncDesc # type: ignore
self._GetFuncDesc(index), # type: ignore
self.ReleaseFuncDesc,
)

def GetVarDesc(self, index: int) -> "VARDESC":
"""Return VARDESC for index"""
return _deref_with_release(
self._GetVarDesc(index), self.ReleaseVarDesc # type: ignore
self._GetVarDesc(index), # type: ignore
self.ReleaseVarDesc,
)

def GetNames(self, memid: int, count: int = 1) -> List[str]:
Expand Down

0 comments on commit 3795c56

Please sign in to comment.