Skip to content

Commit

Permalink
Merge 6d74c1b into f42e0e9
Browse files Browse the repository at this point in the history
  • Loading branch information
tirkarthi committed Apr 14, 2021
2 parents f42e0e9 + 6d74c1b commit f249a6e
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions testslide/strict_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@
import inspect
import os.path
from types import FrameType
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Type, Union
from typing import (
TYPE_CHECKING,
Any,
Callable,
Dict,
List,
Optional,
Type,
Union,
get_type_hints,
)

import testslide.lib
import testslide.mock_callable
Expand Down Expand Up @@ -623,8 +633,12 @@ def __validate_attribute_type(self, name: str, value: Any) -> None:
):
return

if hasattr(self._template, "__annotations__"):
annotations = self._template.__annotations__
if self._template is not None:
try:
annotations = get_type_hints(self._template)
except Exception:
# Some modules can throw KeyError : https://bugs.python.org/issue41515
annotations = {}
if name in annotations:
testslide.lib._validate_argument_type(annotations[name], name, value)

Expand Down

0 comments on commit f249a6e

Please sign in to comment.