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

Fix issue #1318: Type (typehint) error for db.relationship #1320

Open
wants to merge 3 commits into
base: stable
Choose a base branch
from
Open
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
8 changes: 2 additions & 6 deletions src/flask_sqlalchemy/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,9 +952,7 @@ def _set_rel_query(self, kwargs: dict[str, t.Any]) -> None:

backref[1].setdefault("query_class", self.Query)

def relationship(
self, *args: t.Any, **kwargs: t.Any
) -> sa_orm.RelationshipProperty[t.Any]:
def relationship(self, *args: t.Any, **kwargs: t.Any) -> sa_orm.Relationship[t.Any]:
"""A :func:`sqlalchemy.orm.relationship` that applies this extension's
:attr:`Query` class for dynamic relationships and backrefs.

Expand All @@ -976,9 +974,7 @@ def dynamic_loader(
self._set_rel_query(kwargs)
return sa_orm.dynamic_loader(argument, **kwargs)

def _relation(
self, *args: t.Any, **kwargs: t.Any
) -> sa_orm.RelationshipProperty[t.Any]:
def _relation(self, *args: t.Any, **kwargs: t.Any) -> sa_orm.Relationship[t.Any]:
"""A :func:`sqlalchemy.orm.relationship` that applies this extension's
:attr:`Query` class for dynamic relationships and backrefs.

Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ commands = pytest -v --tb=short --basetemp={envtmpdir} {posargs}
deps = pre-commit
skip_install = true
commands = pre-commit run --all-files
allowlist_externals = mypy

[testenv:typing]
deps = -r requirements/typing.txt
commands =
mypy --python-version 3.8
mypy --python-version 3.12
allowlist_externals = mypy

[testenv:docs]
deps = -r requirements/docs.txt
Expand Down