From eae39a47a0fa8de020a456f667ce972152c04229 Mon Sep 17 00:00:00 2001 From: Ashley Sommer Date: Thu, 7 Nov 2024 07:32:27 +1000 Subject: [PATCH] Don't use forward references to TypeAlias where it can be avoided, because autodocs-type-hints doesn't like them. Bump to newer autodocs-type-hints that is desgined for use in Python 3.9. --- poetry.lock | 16 +++++------ pyproject.toml | 2 +- rdflib/graph.py | 71 ++++++++++++++++++++++++++----------------------- 3 files changed, 47 insertions(+), 42 deletions(-) diff --git a/poetry.lock b/poetry.lock index 02a1d7c44..75aa28044 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand. [[package]] name = "alabaster" @@ -1276,22 +1276,22 @@ test = ["cython (>=3.0)", "defusedxml (>=0.7.1)", "pytest (>=8.0)", "setuptools [[package]] name = "sphinx-autodoc-typehints" -version = "2.0.1" +version = "2.3.0" description = "Type hints (PEP 484) support for the Sphinx autodoc extension" optional = false -python-versions = ">=3.8" +python-versions = ">=3.9" files = [ - {file = "sphinx_autodoc_typehints-2.0.1-py3-none-any.whl", hash = "sha256:f73ae89b43a799e587e39266672c1075b2ef783aeb382d3ebed77c38a3fc0149"}, - {file = "sphinx_autodoc_typehints-2.0.1.tar.gz", hash = "sha256:60ed1e3b2c970acc0aa6e877be42d48029a9faec7378a17838716cacd8c10b12"}, + {file = "sphinx_autodoc_typehints-2.3.0-py3-none-any.whl", hash = "sha256:3098e2c6d0ba99eacd013eb06861acc9b51c6e595be86ab05c08ee5506ac0c67"}, + {file = "sphinx_autodoc_typehints-2.3.0.tar.gz", hash = "sha256:535c78ed2d6a1bad393ba9f3dfa2602cf424e2631ee207263e07874c38fde084"}, ] [package.dependencies] -sphinx = ">=7.1.2" +sphinx = ">=7.3.5" [package.extras] docs = ["furo (>=2024.1.29)"] numpy = ["nptyping (>=2.5)"] -testing = ["covdefaults (>=2.3)", "coverage (>=7.4.2)", "diff-cover (>=8.0.3)", "pytest (>=8.0.1)", "pytest-cov (>=4.1)", "sphobjinv (>=2.3.1)", "typing-extensions (>=4.9)"] +testing = ["covdefaults (>=2.3)", "coverage (>=7.4.4)", "defusedxml (>=0.7.1)", "diff-cover (>=9)", "pytest (>=8.1.1)", "pytest-cov (>=5)", "sphobjinv (>=2.3.1)", "typing-extensions (>=4.11)"] [[package]] name = "sphinxcontrib-apidoc" @@ -1495,4 +1495,4 @@ orjson = ["orjson"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<4" -content-hash = "cb88d7ceb933e417e8251fb7ce6c501ee855634433202b2b82db770add59f6a3" +content-hash = "a4e5382d42c7ab09d4191493411f893461b534d92a05344cde1077fe29b5f4b3" diff --git a/pyproject.toml b/pyproject.toml index 54f26d0dd..e99fad09e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,7 +69,7 @@ wheel = ">=0.42,<0.45" sphinx = ">=7.1.2,<8" myst-parser = ">=2,<4" sphinxcontrib-apidoc = ">=0.3,<0.6" -sphinx-autodoc-typehints = ">=1.25.3,<=2.0.1" +sphinx-autodoc-typehints = ">=2.3.0,<2.4.0" typing-extensions = "^4.11.0" [tool.poetry.group.lint.dependencies] diff --git a/rdflib/graph.py b/rdflib/graph.py index ad75d7354..f250d9fa3 100644 --- a/rdflib/graph.py +++ b/rdflib/graph.py @@ -307,56 +307,61 @@ _SubjectType: te.TypeAlias = Union[IdentifiedNode, Literal, Variable] _PredicateType: te.TypeAlias = Union[IdentifiedNode, Variable] _ObjectType: te.TypeAlias = Union[IdentifiedNode, Literal, Variable] -_ContextIdentifierType = IdentifiedNode +_ContextIdentifierType: te.TypeAlias = Union[IdentifiedNode] _TripleType: te.TypeAlias = tuple[_SubjectType, _PredicateType, _ObjectType] +_TriplePathType: te.TypeAlias = tuple[_SubjectType, Path, _ObjectType] +_TripleOrTriplePathType: te.TypeAlias = Union[_TripleType, _TriplePathType] + _QuadType: te.TypeAlias = tuple[ - "_SubjectType", "_PredicateType", "_ObjectType", "_ContextType" + _SubjectType, _PredicateType, _ObjectType, "_ContextType" +] +_OptionalQuadType: te.TypeAlias = tuple[ + _SubjectType, _PredicateType, _ObjectType, Optional["_ContextType"] ] -_OptionalQuadType = tuple[ - "_SubjectType", "_PredicateType", "_ObjectType", Optional["_ContextType"] +_TripleOrOptionalQuadType: te.TypeAlias = Union[_TripleType, _OptionalQuadType] +_OptionalIdentifiedQuadType: te.TypeAlias = tuple[ + _SubjectType, _PredicateType, _ObjectType, Optional[_ContextIdentifierType] ] -_TripleOrOptionalQuadType = Union["_TripleType", "_OptionalQuadType"] -_OptionalQuadQuotedType: te.TypeAlias = Union[_OptionalQuadType, "QuotedGraph"] -_OptionalIdentifiedQuadType = tuple[ - "_SubjectType", "_PredicateType", "_ObjectType", Optional["_ContextIdentifierType"] +_TriplePatternType: te.TypeAlias = tuple[ + Optional[_SubjectType], Optional[_PredicateType], Optional[_ObjectType] ] -_TriplePatternType = tuple[ - Optional["_SubjectType"], Optional["_PredicateType"], Optional["_ObjectType"] +_TriplePathPatternType: te.TypeAlias = tuple[ + Optional[_SubjectType], Path, Optional[_ObjectType] ] -_TriplePathPatternType = tuple[Optional["_SubjectType"], Path, Optional["_ObjectType"]] -_QuadPatternType = tuple[ - Optional["_SubjectType"], - Optional["_PredicateType"], - Optional["_ObjectType"], +_QuadPatternType: te.TypeAlias = tuple[ + Optional[_SubjectType], + Optional[_PredicateType], + Optional[_ObjectType], Optional["_ContextType"], ] -_QuadPathPatternType = tuple[ - Optional["_SubjectType"], +_QuadPathPatternType: te.TypeAlias = tuple[ + Optional[_SubjectType], Path, - Optional["_ObjectType"], + Optional[_ObjectType], Optional["_ContextType"], ] -_TripleOrQuadPatternType = Union["_TriplePatternType", "_QuadPatternType"] -_TripleOrQuadPathPatternType = Union["_TriplePathPatternType", "_QuadPathPatternType"] +_TripleOrQuadPatternType: te.TypeAlias = Union[_TriplePatternType, _QuadPatternType] +_TripleOrQuadPathPatternType: te.TypeAlias = Union[ + _TriplePathPatternType, _QuadPathPatternType +] # The difference between TriplePattern and TripleSelector is that # TripleSelector can have a Optional[Path] as the predicate, and Subject/Object -# can be a QuaotedGraph -_TripleSelectorType = tuple[ - Optional["_SubjectType"], - Optional[Union[Path, "_PredicateType"]], - Optional["_ObjectType"], +# can be a QuotedGraph +_TripleSelectorType: te.TypeAlias = tuple[ + Optional[_SubjectType], + Optional[Union[Path, _PredicateType]], + Optional[_ObjectType], ] -_QuadSelectorType = tuple[ - Optional["_SubjectType"], - Optional[Union[Path, "_PredicateType"]], - Optional["_ObjectType"], +_QuadSelectorType: te.TypeAlias = tuple[ + Optional[_SubjectType], + Optional[Union[Path, _PredicateType]], + Optional[_ObjectType], Optional["_ContextType"], ] -_TripleOrQuadSelectorType = Union["_TripleSelectorType", "_QuadSelectorType"] -_TriplePathType = tuple["_SubjectType", Path, "_ObjectType"] -_TripleOrTriplePathType = Union["_TripleType", "_TriplePathType"] +_TripleOrQuadSelectorType: te.TypeAlias = Union[_TripleSelectorType, _QuadSelectorType] + _GraphT = TypeVar("_GraphT", bound="Graph") _ConjunctiveGraphT = TypeVar("_ConjunctiveGraphT", bound="ConjunctiveGraph") @@ -1951,7 +1956,7 @@ def add_to_cbd(uri: _SubjectType) -> None: return subgraph -_ContextType = Graph +_ContextType: te.TypeAlias = Union[Graph] class ConjunctiveGraph(Graph):