Skip to content

Commit

Permalink
Improve type hint (#1226)
Browse files Browse the repository at this point in the history
  • Loading branch information
pamelafox authored Jun 21, 2023
1 parent cc072bf commit 72cbae3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Version 3.0.5
Unreleased

- ``Pagination.next()`` enforces ``max_per_page``. :issue:`1201`
- Improve type hint for ``get_or_404`` return value to be non-optional. :pr:`1226`


Version 3.0.4
Expand Down
2 changes: 1 addition & 1 deletion src/flask_sqlalchemy/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ def get_binds(self) -> dict[sa.Table, sa.engine.Engine]:

def get_or_404(
self, entity: type[_O], ident: t.Any, *, description: str | None = None
) -> t.Optional[_O]:
) -> _O:
"""Like :meth:`session.get() <sqlalchemy.orm.Session.get>` but aborts with a
``404 Not Found`` error instead of returning ``None``.
Expand Down
3 changes: 2 additions & 1 deletion tests/test_view_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ class Quiz(db.Model):

db.create_all()

item: Quiz = Quiz()
item: Quiz = Quiz(topic="Python")
db.session.add(item)
db.session.commit()
result = db.get_or_404(Quiz, 1)
assert result.topic == "Python"
assert result is item
if hasattr(t, "assert_type"):
t.assert_type(result, Quiz)
Expand Down

0 comments on commit 72cbae3

Please sign in to comment.