Skip to content

Commit

Permalink
Update SQLAlchemy factory base to support generic typing
Browse files Browse the repository at this point in the history
This extends FactoryBoy#1059 to
support SQLAlchemy as well.
  • Loading branch information
goodspark committed Aug 20, 2024
1 parent ac49fb4 commit 7823a14
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ChangeLog
3.3.2 (unreleased)
------------------

- Nothing changed yet.
- Add typing information to SQLAlchemy model factory


3.3.1 (2024-08-18)
Expand Down
5 changes: 4 additions & 1 deletion factory/alchemy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Copyright: See the LICENSE file.

from typing import TypeVar

from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import NoResultFound

Expand All @@ -12,6 +14,7 @@
SESSION_PERSISTENCE_COMMIT,
SESSION_PERSISTENCE_FLUSH,
]
T = TypeVar('T')


class SQLAlchemyOptions(base.FactoryOptions):
Expand Down Expand Up @@ -43,7 +46,7 @@ def _build_default_options(self):
]


class SQLAlchemyModelFactory(base.Factory):
class SQLAlchemyModelFactory(base.Factory[T]):
"""Factory for SQLAlchemy models. """

_options_class = SQLAlchemyOptions
Expand Down

0 comments on commit 7823a14

Please sign in to comment.