litestar-org / litestar-org/polyfactory

Enhancement: add interface for generating arbitrary type

Open
#729 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
1.5k
Forks
120
PR merge metrics
No merged PRs in 30d

Description

### Summary

It is useful for custom field generation or testing to generating an arbitrary type to reuse polyfactory generation logic e.g. `dict[str, list[int]]`. This is not possible without knowledge of internals or creating throwaway model.

### Basic Example

Before
```py
BaseFactory.get_field_value(FieldMeta.from_type(dict[int, str]])
```

After

```py
BaseFactory.get_field_value(dict[int, str])
```
with appropriate overloads to have proper return type. Alternatively could add new method

### Drawbacks and Impact

_No response_

### Unresolved questions

_No response_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at BaseFactory.get_field_value and FieldMeta.from_type, which the issue identifies as the current path for generating values. Trace the existing generation logic and define the public entry point and overload behavior for arbitrary types such as dict[int, str]; done means callers can use the proposed API without constructing FieldMeta or a throwaway model.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.