Skip to content

Commit

Permalink
Add type annotations to functions and methods in _post_coinit/unknwn.
Browse files Browse the repository at this point in the history
  • Loading branch information
junkmd committed Feb 15, 2025
1 parent cba9b6e commit 4105e6c
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions comtypes/_post_coinit/unknwn.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
def _shutdown(
func=_CoUninitialize,
_debug=logger.debug,
):
) -> None:
# Sometimes, CoUninitialize, running at Python shutdown,
# raises an exception. We suppress this when __debug__ is
# False.
Expand Down Expand Up @@ -135,7 +135,7 @@ def __new__(cls, name, bases, namespace):

return self

def __setattr__(self, name, value):
def __setattr__(self, name: str, value: Any) -> None:
if name == "_methods_":
# XXX I'm no longer sure why the code generator generates
# "_methods_ = []" in the interface definition, and later
Expand All @@ -149,11 +149,11 @@ def __setattr__(self, name, value):
self._make_specials()
type.__setattr__(self, name, value)

def _make_specials(self):
def _make_specials(self) -> None:
# This call installs methods that forward the Python protocols
# to COM protocols.

def has_name(name):
def has_name(name: str) -> bool:
# Determine whether a property or method named 'name'
# exists
if self._case_insensitive_:
Expand All @@ -168,7 +168,7 @@ def has_name(name):
if has_name("_NewEnum"):
_meta_patch.iterator(self)

def _make_case_insensitive(self):
def _make_case_insensitive(self) -> None:
# The __map_case__ dictionary maps lower case names to the
# names in the original spelling to enable case insensitive
# method and attribute access.
Expand Down Expand Up @@ -201,7 +201,7 @@ def _make_dispmethods(self, methods: List["_DispMemberSpec"]) -> None:
if self._case_insensitive_:
self.__map_case__[name.lower()] = name

def __get_baseinterface_methodcount(self):
def __get_baseinterface_methodcount(self) -> int:
"Return the number of com methods in the base interfaces"
result = 0
for itf in self.mro()[1:-1]:
Expand Down Expand Up @@ -268,7 +268,7 @@ class _compointer_base(c_void_p, metaclass=_compointer_meta):
if TYPE_CHECKING:
__com_interface__: ClassVar[Type["IUnknown"]]

def __del__(self, _debug=logger.debug):
def __del__(self, _debug=logger.debug) -> None:
"Release the COM refcount we own."
if self:
# comtypes calls CoUninitialize() when the atexit handlers
Expand All @@ -282,26 +282,26 @@ def __del__(self, _debug=logger.debug):
_debug("Release %s", self)
self.Release() # type: ignore

def __eq__(self, other):
def __eq__(self, other) -> bool:
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
)

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

# redefine the .value property; return the object itself.
def __get_value(self):
def __get_value(self) -> "hints.Self":
return self

value = property(__get_value, doc="""Return self.""")

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

Expand Down

0 comments on commit 4105e6c

Please sign in to comment.