Skip to content

Commit

Permalink
Merge branch 'main' into add-recursion-guard
Browse files Browse the repository at this point in the history
  • Loading branch information
guacs authored Jan 16, 2024
2 parents b444845 + 40538c9 commit 21d4cdc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion polyfactory/factories/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def __init_subclass__(cls, *args: Any, **kwargs: Any) -> None: # noqa: C901
if random_seed is not None:
cls.seed_random(random_seed)

if cls.__set_as_default_factory_for_type__:
if cls.__set_as_default_factory_for_type__ and hasattr(cls, "__model__"):
BaseFactory._factory_type_mapping[cls.__model__] = cls

@classmethod
Expand Down
20 changes: 20 additions & 0 deletions tests/test_factory_configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import Any, Type

from typing_extensions import TypeGuard

from polyfactory.factories.base import BaseFactory, T


def test_setting_set_as_default_factory_for_type_on_base_factory() -> None:
"""Setting the value to `True` shouldn't raise exception when initializing."""

class CustomBaseFactory(BaseFactory[T]):
__is_base_factory__ = True
__set_as_default_factory_for_type__ = True

@classmethod
def is_supported_type(cls, value: Any) -> TypeGuard[Type[T]]:
# Set this as false since this factory will be injected into the
# list of base factories, but this obviously shouldn't be ran
# for any of the types.
return False

0 comments on commit 21d4cdc

Please sign in to comment.