Skip to content

Commit

Permalink
chore: improve safe_issubclass
Browse files Browse the repository at this point in the history
  • Loading branch information
PrettyWood committed Jul 29, 2020
1 parent 53b8752 commit 7ebb75c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pydantic/schema.py
Expand Up @@ -638,8 +638,11 @@ def field_singleton_sub_fields_schema(


def safe_issubclass(a: Any, b: Any) -> bool:
# `typing.Pattern` is not a valid type
return issubclass(a, b) if a is not Pattern else (a is b)
"""If `a` is not a valid class (e.g. `typing.Pattern`), `issubclass` works only if `a is b`"""
try:
return issubclass(a, b)
except TypeError:
return False


def add_field_type_to_schema(field_type: Any, schema: Dict[str, Any]) -> None:
Expand Down

0 comments on commit 7ebb75c

Please sign in to comment.