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: def _is_starlette_request_cls(self, instance: object) -> bool:
return starlette \ return starlette \
and isinstance(instance, type) \ and isinstance(instance, type) \
and self._safe_is_subclass(instance, starlette.requests.Request) and _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
def _is_builtin(self, instance: object) -> bool: def _is_builtin(self, instance: object) -> bool:
return inspect.isbuiltin(instance) return inspect.isbuiltin(instance)
@ -685,6 +679,13 @@ def _is_declarative_container(instance: Any) -> bool:
and getattr(instance, "declarative_parent", None) is None) 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: class Modifier:
def modify( def modify(

View File

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