Skip to content

Commit

Permalink
Fixed warnings about un-annotated class/static methods being instrume…
Browse files Browse the repository at this point in the history
…nted
  • Loading branch information
agronholm committed Nov 11, 2019
1 parent da05d39 commit 0341d72
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions tests/dummymodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ def type_checked_classmethod(cls, x: int, y: int) -> int:
def type_checked_staticmethod(x: int, y: int) -> int:
return x * y

@classmethod
def undocumented_classmethod(cls, x, y):
pass

@staticmethod
def undocumented_staticmethod(x, y):
pass


def outer():
class Inner:
Expand Down
5 changes: 3 additions & 2 deletions typeguard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,9 @@ class with this decorator.
if attr.__qualname__.startswith(prefix) and getattr(attr, '__annotations__', None):
setattr(func, key, typechecked(attr, always=always, _localns=func.__dict__))
elif isinstance(attr, (classmethod, staticmethod)):
wrapped = typechecked(attr.__func__, always=always, _localns=func.__dict__)
setattr(func, key, type(attr)(wrapped))
if getattr(attr.__func__, '__annotations__', None):
wrapped = typechecked(attr.__func__, always=always, _localns=func.__dict__)
setattr(func, key, type(attr)(wrapped))

return func

Expand Down

0 comments on commit 0341d72

Please sign in to comment.