Skip to content

Commit

Permalink
Fixed performance issue caused by the use of getattr_static()
Browse files Browse the repository at this point in the history
Fixes #104.
  • Loading branch information
agronholm committed Dec 27, 2019
1 parent 47a2f5c commit 5feb055
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ This library adheres to `Semantic Versioning 2.0 <https://semver.org/#semantic-v

- Fixed ``@typechecked`` returning ``None`` when called with ``always=True`` and Python runs in
optimized mode
- Fixed performance regression introduced in v2.7.0 (the ``getattr_static()`` call was causing a 3x
slowdown)

**2.7.0** (2019-12-10)

Expand Down
4 changes: 2 additions & 2 deletions typeguard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from collections import OrderedDict
from enum import Enum
from functools import wraps, partial
from inspect import Parameter, isclass, isfunction, isgeneratorfunction, getattr_static
from inspect import Parameter, isclass, isfunction, isgeneratorfunction
from io import TextIOBase, RawIOBase, IOBase, BufferedIOBase
from traceback import extract_stack, print_stack
from types import CodeType, FunctionType
Expand Down Expand Up @@ -582,7 +582,7 @@ def check_type(argname: str, value, expected_type, memo: Optional[_CallMemo] = N
check_io(argname, value, expected_type)
elif issubclass(expected_type, dict) and hasattr(expected_type, '__annotations__'):
check_typed_dict(argname, value, expected_type, memo)
elif getattr_static(expected_type, '_is_protocol', False):
elif getattr(expected_type, '_is_protocol', False):
check_protocol(argname, value, expected_type)
else:
expected_type = (getattr(expected_type, '__extra__', None) or origin_type or
Expand Down

0 comments on commit 5feb055

Please sign in to comment.