Skip to content

Commit

Permalink
Fixed AttributeError when using @TypeChecked on a metaclass
Browse files Browse the repository at this point in the history
Fixes #88.
  • Loading branch information
agronholm committed Nov 8, 2019
1 parent a96a01b commit c4e8646
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This library adheres to `Semantic Versioning 2.0 <https://semver.org/#semantic-v

- Fixed import errors when using the import hook and trying to import a module that has both a
module docstring and ``__future__`` imports in it
- Fixed ``AttributeError`` when using @typechecked on a metaclass

**2.6.0** (2019-11-06)

Expand Down
6 changes: 5 additions & 1 deletion tests/dummymodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ def inner(x: argtype) -> return_annotation:
return inner(arg)


class DummyClass:
class Metaclass(type):
pass


class DummyClass(metaclass=Metaclass):
def type_checked_method(self, x: int, y: int) -> int:
return x * y

Expand Down
2 changes: 1 addition & 1 deletion typeguard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ class with this decorator.
if isclass(func):
prefix = func.__qualname__ + '.'
for key in dir(func):
attr = getattr(func, key)
attr = getattr(func, key, None)
if callable(attr) and attr.__qualname__.startswith(prefix):
if getattr(attr, '__annotations__', None):
setattr(func, key, typechecked(attr, always=always))
Expand Down

0 comments on commit c4e8646

Please sign in to comment.