diff --git a/pydantic/__manifest__.py b/pydantic/__manifest__.py index 9ed053c8..df4e562e 100644 --- a/pydantic/__manifest__.py +++ b/pydantic/__manifest__.py @@ -15,10 +15,7 @@ "data": [], "demo": [], "external_dependencies": { - "python": [ - "pydantic", - "contextvars", - ] + "python": ["pydantic", "contextvars", "typing-extensions>=4.0.1"] }, "installable": True, } diff --git a/pydantic/models.py b/pydantic/models.py index bf5f00b6..12f36b0c 100644 --- a/pydantic/models.py +++ b/pydantic/models.py @@ -151,7 +151,7 @@ def __subclasscheck__(cls, subclass): # noqa: B902 """Implement issubclass(sub, cls).""" if hasattr(subclass, "_original_cls"): return cls.__subclasscheck__(subclass._original_cls) - return super().__subclasscheck__(subclass) + return isinstance(subclass, type) and super().__subclasscheck__(subclass) class BaseModel(pydantic.BaseModel, metaclass=ExtendablePydanticModelMeta): diff --git a/pydantic/tests/test_pydantic.py b/pydantic/tests/test_pydantic.py index 76d2133e..7853e11b 100644 --- a/pydantic/tests/test_pydantic.py +++ b/pydantic/tests/test_pydantic.py @@ -3,6 +3,11 @@ from typing import List +try: + from typing import Literal +except ImportError: + from typing_extensions import Literal + import pydantic from .. import models, utils @@ -154,3 +159,18 @@ class ExtendedLocation(Location, extends=Location): inst2 = ExtendedLocation.construct() self.assertEqual(inst1.__class__, inst2.__class__) self.assertEqual(inst1.schema(), inst2.schema()) + + def test_issubclass(self): + """In this test we check that issublass is lenient when used with + GenericAlias + """ + self.assertFalse(issubclass(Literal["test"], models.BaseModel)) + self.assertFalse(issubclass(Literal, models.BaseModel)) + + class Location(models.BaseModel): + kind: Literal["view", "bin"] + my_list: List[str] + + self._build_pydantic_classes(Location) + schema = Location.schema() + self.assertTrue(schema) diff --git a/requirements.txt b/requirements.txt index 20c95515..1a1ac266 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,3 +9,4 @@ marshmallow-objects>=2.0.0 parse-accept-language pydantic pyquerystring +typing-extensions>=4.0.1