Skip to content

Commit

Permalink
Fix _is_same_module() on PyPy
Browse files Browse the repository at this point in the history
Fix `_is_same_module()` to account for `__module__` attribute possibly
being `None`, as it currently is in PyPy, rather than non-present,
as it is in CPython.

Fixes #118
  • Loading branch information
mgorny authored and mkorpela committed Jan 20, 2024
1 parent 16f322b commit c870e64
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions overrides/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ def _get_type_hints(callable) -> Optional[Dict]:

def _is_same_module(callable1: _WrappedMethod, callable2: _WrappedMethod2) -> bool:
mod1 = callable1.__module__.split(".")[0]
try:
mod2 = callable2.__module__
except AttributeError:
# "__module__" attribute may be missing in CPython or it can be None
# in PyPy: https://github.com/mkorpela/overrides/issues/118
mod2 = getattr(callable2, "__module__", None)
if mod2 is None:
return False
mod2 = mod2.split(".")[0]
return mod1 == mod2
Expand Down

0 comments on commit c870e64

Please sign in to comment.