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 9148cc7
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)
"""Support types that are not valid classes (e.g. `typing.Pattern`)"""
try:
return issubclass(a, b)
except TypeError:
return a is b


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

0 comments on commit 9148cc7

Please sign in to comment.