Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use forward references to TypeAlias where it can be avoided #2973

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
71 changes: 38 additions & 33 deletions rdflib/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -1951,7 +1956,7 @@ def add_to_cbd(uri: _SubjectType) -> None:
return subgraph


_ContextType = Graph
_ContextType: te.TypeAlias = Union[Graph]


class ConjunctiveGraph(Graph):
Expand Down
Loading