diff --git a/synapse/_pydantic_compat.py b/synapse/_pydantic_compat.py
index a6ceeb04d2..f0eedf5c6d 100644
--- a/synapse/_pydantic_compat.py
+++ b/synapse/_pydantic_compat.py
@@ -19,6 +19,8 @@
#
#
+from typing import TYPE_CHECKING
+
from packaging.version import Version
try:
@@ -30,4 +32,64 @@ except ImportError:
HAS_PYDANTIC_V2: bool = Version(pydantic_version).major == 2
-__all__ = ("HAS_PYDANTIC_V2",)
+if TYPE_CHECKING or HAS_PYDANTIC_V2:
+ from pydantic.v1 import (
+ BaseModel,
+ Extra,
+ Field,
+ MissingError,
+ PydanticValueError,
+ StrictBool,
+ StrictInt,
+ StrictStr,
+ ValidationError,
+ conbytes,
+ confloat,
+ conint,
+ constr,
+ parse_obj_as,
+ validator,
+ )
+ from pydantic.v1.error_wrappers import ErrorWrapper
+ from pydantic.v1.typing import get_args
+else:
+ from pydantic import (
+ BaseModel,
+ Extra,
+ Field,
+ MissingError,
+ PydanticValueError,
+ StrictBool,
+ StrictInt,
+ StrictStr,
+ ValidationError,
+ conbytes,
+ confloat,
+ conint,
+ constr,
+ parse_obj_as,
+ validator,
+ )
+ from pydantic.error_wrappers import ErrorWrapper
+ from pydantic.typing import get_args
+
+__all__ = (
+ "HAS_PYDANTIC_V2",
+ "BaseModel",
+ "constr",
+ "conbytes",
+ "conint",
+ "confloat",
+ "ErrorWrapper",
+ "Extra",
+ "Field",
+ "get_args",
+ "MissingError",
+ "parse_obj_as",
+ "PydanticValueError",
+ "StrictBool",
+ "StrictInt",
+ "StrictStr",
+ "ValidationError",
+ "validator",
+)
|