From 3cf846ee233146a693330a6f895498fb1d5c666b Mon Sep 17 00:00:00 2001 From: collerek Date: Tue, 12 Jan 2021 15:28:35 +0100 Subject: [PATCH] add internal forwardref stub --- ormar/fields/foreign_key.py | 3 ++- ormar/fields/many_to_many.py | 3 ++- ormar/models/helpers/models.py | 3 ++- ormar/protocols/forward_ref.py | 22 ++++++++++++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 ormar/protocols/forward_ref.py diff --git a/ormar/fields/foreign_key.py b/ormar/fields/foreign_key.py index e93a2bc..efddbe9 100644 --- a/ormar/fields/foreign_key.py +++ b/ormar/fields/foreign_key.py @@ -3,12 +3,13 @@ from dataclasses import dataclass from typing import Any, List, Optional, TYPE_CHECKING, Tuple, Type, Union from pydantic import BaseModel, create_model -from pydantic.typing import ForwardRef, evaluate_forwardref +from pydantic.typing import evaluate_forwardref from sqlalchemy import UniqueConstraint import ormar # noqa I101 from ormar.exceptions import RelationshipInstanceError from ormar.fields.base import BaseField +from ormar.protocols.forward_ref import ForwardRef if TYPE_CHECKING: # pragma no cover from ormar.models import Model, NewBaseModel diff --git a/ormar/fields/many_to_many.py b/ormar/fields/many_to_many.py index ae77364..75e84bd 100644 --- a/ormar/fields/many_to_many.py +++ b/ormar/fields/many_to_many.py @@ -1,9 +1,10 @@ from typing import Any, List, Optional, TYPE_CHECKING, Tuple, Type, Union -from pydantic.typing import ForwardRef, evaluate_forwardref +from pydantic.typing import evaluate_forwardref import ormar # noqa: I100 from ormar.fields import BaseField from ormar.fields.foreign_key import ForeignKeyField +from ormar.protocols.forward_ref import ForwardRef if TYPE_CHECKING: # pragma no cover from ormar.models import Model diff --git a/ormar/models/helpers/models.py b/ormar/models/helpers/models.py index f7aeeeb..feaa3cf 100644 --- a/ormar/models/helpers/models.py +++ b/ormar/models/helpers/models.py @@ -1,9 +1,10 @@ from typing import Dict, List, Optional, TYPE_CHECKING, Tuple, Type -from pydantic.typing import ForwardRef + import ormar # noqa: I100 from ormar.fields.foreign_key import ForeignKeyField from ormar.models.helpers.pydantic import populate_pydantic_default_values +from ormar.protocols.forward_ref import ForwardRef if TYPE_CHECKING: # pragma no cover from ormar import Model diff --git a/ormar/protocols/forward_ref.py b/ormar/protocols/forward_ref.py new file mode 100644 index 0000000..d03429f --- /dev/null +++ b/ormar/protocols/forward_ref.py @@ -0,0 +1,22 @@ +import sys +from typing import Any, TYPE_CHECKING + +if sys.version_info < (3, 7): # pragma: no cover + if TYPE_CHECKING: + + class ForwardRef: + + _gorg = None + + def __init__(self, args: Any) -> None: + pass + + def _eval_type(self, globalns: Any, localns: Any) -> Any: + pass + + else: + from typing import _ForwardRef as ForwardRef +else: + from typing import ForwardRef + +ForwardRef = ForwardRef