Skip to content

Commit

Permalink
chore: drop testing for EOL Python 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
mak626 committed Jan 15, 2024
1 parent 014c6ff commit 58135e7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v3
Expand Down
13 changes: 7 additions & 6 deletions graphene_pydantic/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
UUID,
Union,
)
from graphene.types.base import BaseType
from graphene.types.datetime import Date, DateTime, Time
from pydantic import BaseModel
from pydantic.fields import FieldInfo
from pydantic_core import PydanticUndefined

from .registry import Registry
from .registry import Placeholder, Registry
from .util import construct_union_class_name, evaluate_forward_ref

PYTHON10 = sys.version_info >= (3, 10)
Expand Down Expand Up @@ -175,7 +176,7 @@ def convert_pydantic_type(
registry: Registry,
parent_type: T.Type = None,
model: T.Type[BaseModel] = None,
) -> Type: # noqa: C901
) -> T.Union[Type[T.Union[BaseType, List]], Placeholder]: # noqa: C901
"""
Convert a Pydantic type to a Graphene Field type, including not just the
native Python type but any additional metadata (e.g. shape) that Pydantic
Expand All @@ -197,7 +198,7 @@ def find_graphene_type(
registry: Registry,
parent_type: T.Type = None,
model: T.Type[BaseModel] = None,
) -> Type: # noqa: C901
) -> T.Union[Type[T.Union[BaseType, List]], Placeholder]: # noqa: C901
"""
Map a native Python type to a Graphene-supported Field type, where possible,
throwing an error if we don't know what to map it to.
Expand Down Expand Up @@ -303,10 +304,10 @@ def convert_generic_python_type(
registry: Registry,
parent_type: T.Type = None,
model: T.Type[BaseModel] = None,
) -> Type: # noqa: C901
) -> T.Union[Type[T.Union[BaseType, List]], Placeholder]: # noqa: C901
"""
Convert annotated Python generic types into the most appropriate Graphene
Field type -- e.g. turn `typing.Union` into a Graphene Union.
Field type -- e.g., turn `typing.Union` into a Graphene Union.
"""
origin = type_.__origin__
if not origin: # pragma: no cover # this really should be impossible
Expand Down Expand Up @@ -393,7 +394,7 @@ def convert_literal_type(
registry: Registry,
parent_type: T.Type = None,
model: T.Type[BaseModel] = None,
):
) -> T.Union[Type[T.Union[BaseType, List]], Placeholder]:
"""
Convert an annotated Python Literal type into a Graphene Scalar or Union of Scalars.
"""
Expand Down
4 changes: 2 additions & 2 deletions graphene_pydantic/inputobjecttype.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def __init_subclass_with_meta__(
_meta=None,
**options,
):
assert (
model and issubclass(model, pydantic.BaseModel)
assert model and issubclass(
model, pydantic.BaseModel
), f'You need to pass a valid Pydantic model in {cls.__name__}.Meta, received "{model}"'

assert isinstance(
Expand Down
4 changes: 2 additions & 2 deletions graphene_pydantic/objecttype.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def __init_subclass_with_meta__(
_meta=None,
**options,
):
assert (
model and issubclass(model, pydantic.BaseModel)
assert model and issubclass(
model, pydantic.BaseModel
), f'You need to pass a valid Pydantic model in {cls.__name__}.Meta, received "{model}"'

assert isinstance(
Expand Down
7 changes: 5 additions & 2 deletions graphene_pydantic/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from collections import defaultdict
from typing import Dict, Generic, Optional, Type, TypeVar, Union

from graphene.types.base import BaseType
from pydantic import BaseModel
from pydantic.fields import FieldInfo

Expand Down Expand Up @@ -39,7 +40,7 @@ class Registry(Generic[T]):

def __init__(self, required_obj_type: ObjectType):
self._required_obj_type: ObjectType = required_obj_type
self._registry: Dict[ModelType, Output] = {}
self._registry: Dict[ModelType, Union[Type[BaseType], Placeholder]] = {}
self._registry_object_fields: Dict[
ObjectType, Dict[str, FieldInfo]
] = defaultdict(dict)
Expand All @@ -52,7 +53,9 @@ def register(self, obj_type: ObjectType):
), "Can't register models linked to another Registry"
self._registry[obj_type._meta.model] = obj_type

def get_type_for_model(self, model: ModelType) -> Optional[Output]:
def get_type_for_model(
self, model: ModelType
) -> Union[Type[BaseType], Placeholder]:
return self._registry.get(model)

def add_placeholder_for_model(self, model: ModelType):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ classifiers = [
keywords = ["api", "graphql", "protocol", "rest", "relay", "graphene", "pydantic", "model"]

[tool.poetry.dependencies]
python = "^3.7"
python = "^3.8"
graphene = ">=2.1.8"
pydantic = ">=2.0"

Expand Down

0 comments on commit 58135e7

Please sign in to comment.