Refactor + add tests to #569

This commit is contained in:
Roman Mogylatov 2022-03-27 14:18:46 -04:00
parent 8fe00bcff0
commit c2877777af
2 changed files with 10 additions and 8 deletions

View File

@ -321,13 +321,7 @@ class InspectFilter:
def _is_starlette_request_cls(self, instance: object) -> bool:
return starlette \
and isinstance(instance, type) \
and self._safe_is_subclass(instance, starlette.requests.Request)
def _safe_is_subclass(self, instance: type, cls: type) -> bool:
try:
return issubclass(instance, cls)
except TypeError:
return False
and _safe_is_subclass(instance, starlette.requests.Request)
def _is_builtin(self, instance: object) -> bool:
return inspect.isbuiltin(instance)
@ -685,6 +679,13 @@ def _is_declarative_container(instance: Any) -> bool:
and getattr(instance, "declarative_parent", None) is None)
def _safe_is_subclass(instance: Any, cls: Type) -> bool:
try:
return issubclass(instance, cls)
except TypeError:
return False
class Modifier:
def modify(

View File

@ -5,6 +5,7 @@ import sys
if "pypy" not in sys.version.lower():
import numpy # noqa
from numpy import * # noqa
if sys.version_info >= (3, 7):
from numpy.typing import * # noqa
import scipy # noqa