Skip to content

Commit

Permalink
Add missing generic on Factory subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Feb 6, 2024
1 parent 68de8e7 commit 56f1dd9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
6 changes: 5 additions & 1 deletion factory/alchemy.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Copyright: See the LICENSE file.

from typing import TypeVar

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

from . import base, errors

T = TypeVar("T")

SESSION_PERSISTENCE_COMMIT = 'commit'
SESSION_PERSISTENCE_FLUSH = 'flush'
VALID_SESSION_PERSISTENCE_TYPES = [
Expand Down Expand Up @@ -46,7 +50,7 @@ def _build_default_options(self):
]


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

_options_class = SQLAlchemyOptions
Expand Down
10 changes: 5 additions & 5 deletions factory/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ def __init__(self, **kwargs):
setattr(self, field, value)


class StubFactory(Factory):
class StubFactory(Factory[T]):

class Meta:
strategy = enums.STUB_STRATEGY
Expand All @@ -671,7 +671,7 @@ def create(cls, **kwargs):
raise errors.UnsupportedStrategy()


class BaseDictFactory(Factory):
class BaseDictFactory(Factory[T]):
"""Factory for dictionary-like classes."""
class Meta:
abstract = True
Expand All @@ -688,12 +688,12 @@ def _create(cls, model_class, *args, **kwargs):
return cls._build(model_class, *args, **kwargs)


class DictFactory(BaseDictFactory):
class DictFactory(BaseDictFactory[T]):
class Meta:
model = dict


class BaseListFactory(Factory):
class BaseListFactory(Factory[T]):
"""Factory for list-like classes."""
class Meta:
abstract = True
Expand All @@ -714,7 +714,7 @@ def _create(cls, model_class, *args, **kwargs):
return cls._build(model_class, *args, **kwargs)


class ListFactory(BaseListFactory):
class ListFactory(BaseListFactory[T]):
class Meta:
model = list

Expand Down
5 changes: 3 additions & 2 deletions factory/mogo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@


"""factory_boy extensions for use with the mogo library (pymongo wrapper)."""

from typing import TypeVar

from . import base

T = TypeVar("T")

class MogoFactory(base.Factory):
class MogoFactory(base.Factory[T]):
"""Factory for mogo objects."""
class Meta:
abstract = True
Expand Down
5 changes: 3 additions & 2 deletions factory/mongoengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@


"""factory_boy extensions for use with the mongoengine library (pymongo wrapper)."""

from typing import TypeVar

from . import base

T = TypeVar("T")

class MongoEngineFactory(base.Factory):
class MongoEngineFactory(base.Factory[T]):
"""Factory for mongoengine objects."""

class Meta:
Expand Down

0 comments on commit 56f1dd9

Please sign in to comment.