summaryrefslogtreecommitdiff
path: root/venv/lib/python3.11/site-packages/polyfactory/collection_extender.py
diff options
context:
space:
mode:
authorcyfraeviolae <cyfraeviolae>2024-04-03 03:17:55 -0400
committercyfraeviolae <cyfraeviolae>2024-04-03 03:17:55 -0400
commit12cf076118570eebbff08c6b3090e0d4798447a1 (patch)
tree3ba25e17e3c3a5e82316558ba3864b955919ff72 /venv/lib/python3.11/site-packages/polyfactory/collection_extender.py
parentc45662ff3923b34614ddcc8feb9195541166dcc5 (diff)
no venv
Diffstat (limited to 'venv/lib/python3.11/site-packages/polyfactory/collection_extender.py')
-rw-r--r--venv/lib/python3.11/site-packages/polyfactory/collection_extender.py89
1 files changed, 0 insertions, 89 deletions
diff --git a/venv/lib/python3.11/site-packages/polyfactory/collection_extender.py b/venv/lib/python3.11/site-packages/polyfactory/collection_extender.py
deleted file mode 100644
index 6377125..0000000
--- a/venv/lib/python3.11/site-packages/polyfactory/collection_extender.py
+++ /dev/null
@@ -1,89 +0,0 @@
-from __future__ import annotations
-
-import random
-from abc import ABC, abstractmethod
-from collections import deque
-from typing import Any
-
-from polyfactory.utils.predicates import is_safe_subclass
-
-
-class CollectionExtender(ABC):
- __types__: tuple[type, ...]
-
- @staticmethod
- @abstractmethod
- def _extend_type_args(type_args: tuple[Any, ...], number_of_args: int) -> tuple[Any, ...]:
- raise NotImplementedError
-
- @classmethod
- def _subclass_for_type(cls, annotation_alias: Any) -> type[CollectionExtender]:
- return next(
- (
- subclass
- for subclass in cls.__subclasses__()
- if any(is_safe_subclass(annotation_alias, t) for t in subclass.__types__)
- ),
- FallbackExtender,
- )
-
- @classmethod
- def extend_type_args(
- cls,
- annotation_alias: Any,
- type_args: tuple[Any, ...],
- number_of_args: int,
- ) -> tuple[Any, ...]:
- return cls._subclass_for_type(annotation_alias)._extend_type_args(type_args, number_of_args)
-
-
-class TupleExtender(CollectionExtender):
- __types__ = (tuple,)
-
- @staticmethod
- def _extend_type_args(type_args: tuple[Any, ...], number_of_args: int) -> tuple[Any, ...]:
- if not type_args:
- return type_args
- if type_args[-1] is not ...:
- return type_args
- type_to_extend = type_args[-2]
- return type_args[:-2] + (type_to_extend,) * number_of_args
-
-
-class ListLikeExtender(CollectionExtender):
- __types__ = (list, deque)
-
- @staticmethod
- def _extend_type_args(type_args: tuple[Any, ...], number_of_args: int) -> tuple[Any, ...]:
- if not type_args:
- return type_args
- return tuple(random.choice(type_args) for _ in range(number_of_args))
-
-
-class SetExtender(CollectionExtender):
- __types__ = (set, frozenset)
-
- @staticmethod
- def _extend_type_args(type_args: tuple[Any, ...], number_of_args: int) -> tuple[Any, ...]:
- if not type_args:
- return type_args
- return tuple(random.choice(type_args) for _ in range(number_of_args))
-
-
-class DictExtender(CollectionExtender):
- __types__ = (dict,)
-
- @staticmethod
- def _extend_type_args(type_args: tuple[Any, ...], number_of_args: int) -> tuple[Any, ...]:
- return type_args * number_of_args
-
-
-class FallbackExtender(CollectionExtender):
- __types__ = ()
-
- @staticmethod
- def _extend_type_args(
- type_args: tuple[Any, ...],
- number_of_args: int, # noqa: ARG004
- ) -> tuple[Any, ...]: # - investigate @guacs
- return type_args