Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add_providers to easily add new type provider #659

Merged
merged 6 commits into from
Mar 19, 2025

Conversation

iloveitaly
Copy link
Contributor

Description

Without modifying the factory class. This enables 3rd party custom types to easily add providers.

@iloveitaly iloveitaly requested a review from guacs as a code owner March 15, 2025 22:03
Copy link
Member

@cofin cofin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Let's let a few other take a look before merging though.

@iloveitaly
Copy link
Contributor Author

Friendly reminder on this pull request. Please provide any updates or additional information if needed.

@provinzkraut
Copy link
Member

@adhtruong?

Copy link
Collaborator

@adhtruong adhtruong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change and feature looks good!

Things to update

  • Small copy and formatting update
  • Can docs be updated with an example to allow discoverability? Maybe under docs/usage/configuration?

@iloveitaly
Copy link
Contributor Author

Merged your changes in and added a docs example!

@iloveitaly iloveitaly force-pushed the add-providers branch 2 times, most recently from c804f9c to b23a2dd Compare March 18, 2025 19:37
Copy link
Collaborator

@adhtruong adhtruong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating and work on this!

iloveitaly and others added 6 commits March 19, 2025 08:32
@adhtruong adhtruong enabled auto-merge (squash) March 19, 2025 08:32
@adhtruong adhtruong merged commit 33c72e7 into litestar-org:main Mar 19, 2025
25 checks passed
Copy link

Documentation preview will be available shortly at https://litestar-org.github.io/polyfactory-docs-preview/659

@adhtruong
Copy link
Collaborator

@all-contributors add @iloveitaly for code doc

Copy link
Contributor

@adhtruong

I've put up a pull request to add @iloveitaly! 🎉

@dimk00z
Copy link

dimk00z commented Mar 20, 2025

@all-contributors add @iloveitaly for code doc

Hi, I'm looking forward that cool feature in the next version. Any plans when?

Copy link
Contributor

@dimk00z

@iloveitaly already contributed before to code, doc

github-merge-queue bot pushed a commit to mozilla/experimenter that referenced this pull request Mar 25, 2025
Bumps [polyfactory](https://github.com/litestar-org/polyfactory) from
2.19.0 to 2.20.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/litestar-org/polyfactory/releases">polyfactory's
releases</a>.</em></p>
<blockquote>
<h2>v2.20.0</h2>
<h1>Sponsors 🌟</h1>
<p>A huge 'Thank you!' to all other sponsors across <a
href="https://polar.sh/litestar-org">Polar.sh</a>, <a
href="https://opencollective.com/litestar">OpenCollective</a> and <a
href="https://github.com/sponsors/litestar-org/">GitHub
Sponsors</a>!</p>
<h2>What's Changed</h2>
<p>### New Features 🚀</p>
<ul>
<li>feat: described an ability to use async data in factory fields;
refactored factories/base and some tests by <a
href="https://github.com/nisemenov"><code>@​nisemenov</code></a> in <a
href="https://redirect.github.com/litestar-org/polyfactory/pull/641">litestar-org/polyfactory#641</a></li>
<li>feat: simplify pytest plugin by <a
href="https://github.com/adhtruong"><code>@​adhtruong</code></a> in <a
href="https://redirect.github.com/litestar-org/polyfactory/pull/652">litestar-org/polyfactory#652</a></li>
<li>feat: add_providers to easily add new type provider by <a
href="https://github.com/iloveitaly"><code>@​iloveitaly</code></a> in <a
href="https://redirect.github.com/litestar-org/polyfactory/pull/659">litestar-org/polyfactory#659</a></li>
<li>feat: improve random range by <a
href="https://github.com/adhtruong"><code>@​adhtruong</code></a> in <a
href="https://redirect.github.com/litestar-org/polyfactory/pull/653">litestar-org/polyfactory#653</a></li>
<li>feat: improve create factory typing by <a
href="https://github.com/adhtruong"><code>@​adhtruong</code></a> in <a
href="https://redirect.github.com/litestar-org/polyfactory/pull/657">litestar-org/polyfactory#657</a></li>
</ul>
<p>### Fixes 🔧</p>
<ul>
<li>fix: allow non-hashable type args by <a
href="https://github.com/adhtruong"><code>@​adhtruong</code></a> in <a
href="https://redirect.github.com/litestar-org/polyfactory/pull/643">litestar-org/polyfactory#643</a></li>
<li>fix(pyproject.toml): dont allow faker version less then 5.0.0 by <a
href="https://github.com/T0nd0Tara"><code>@​T0nd0Tara</code></a> in <a
href="https://redirect.github.com/litestar-org/polyfactory/pull/646">litestar-org/polyfactory#646</a></li>
<li>build: update dependencies and ignores by <a
href="https://github.com/adhtruong"><code>@​adhtruong</code></a> in <a
href="https://redirect.github.com/litestar-org/polyfactory/pull/648">litestar-org/polyfactory#648</a></li>
<li>fix(<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/634">#634</a>):
added a generate function to support SQL Numeric field by <a
href="https://github.com/nisemenov"><code>@​nisemenov</code></a> in <a
href="https://redirect.github.com/litestar-org/polyfactory/pull/636">litestar-org/polyfactory#636</a></li>
<li>fix: ignore dataclass types in pydantic field parsing by <a
href="https://github.com/adhtruong"><code>@​adhtruong</code></a> in <a
href="https://redirect.github.com/litestar-org/polyfactory/pull/660">litestar-org/polyfactory#660</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a href="https://github.com/T0nd0Tara"><code>@​T0nd0Tara</code></a>
made their first contribution in <a
href="https://redirect.github.com/litestar-org/polyfactory/pull/646">litestar-org/polyfactory#646</a></li>
<li><a
href="https://github.com/iloveitaly"><code>@​iloveitaly</code></a> made
their first contribution in <a
href="https://redirect.github.com/litestar-org/polyfactory/pull/659">litestar-org/polyfactory#659</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/litestar-org/polyfactory/compare/v2.19.0...v2.20.0">https://github.com/litestar-org/polyfactory/compare/v2.19.0...v2.20.0</a></p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/litestar-org/polyfactory/blob/main/docs/changelog.rst">polyfactory's
changelog</a>.</em></p>
<blockquote>
<h1>=========
Changelog</h1>
<p>All commits to this project will be documented in this file.</p>
<h2>[unreleased]</h2>
<p><code>de78949
&lt;https://github.com/litestar-org/polyfactory/commit/de789499f8b16b49c9fae5954cfba8ad868fff58&gt;</code>_
is the last commit in the changelog before unreleased changes.</p>
<p>Bug Fixes

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</p>
<ul>
<li>(<code>64fa119
&lt;https://github.com/litestar-org/polyfactory/commit/64fa119f7caa2d8c616e3dc2c50ae9c232616351&gt;</code><em>)
- Allow non-hashable type args (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/643">#643</a>)
by <code>@adhtruong &lt;https://github.com/adhtruong&gt;</code></em> in
<code>[#643](litestar-org/polyfactory#643)
&lt;https://github.com/litestar-org/polyfactory/pull/643&gt;</code>_</li>
<li>(<code>703aa2e
&lt;https://github.com/litestar-org/polyfactory/commit/703aa2ef2d2b2489b0c817f6f0d9e75714e1069b&gt;</code><em>)
- Dont allow faker version less then 5.0.0 (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/646">#646</a>)
by <code>@T0nd0Tara &lt;https://github.com/T0nd0Tara&gt;</code></em> in
<code>[#646](litestar-org/polyfactory#646)
&lt;https://github.com/litestar-org/polyfactory/pull/646&gt;</code>_</li>
<li>(<code>e4a27ca
&lt;https://github.com/litestar-org/polyfactory/commit/e4a27cab597f60f142210eaca66a3f97188810f0&gt;</code><em>)
- Added a generate function to support SQL Numeric field (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/636">#636</a>)
by <code>@nisemenov &lt;https://github.com/nisemenov&gt;</code></em> in
<code>[#636](litestar-org/polyfactory#636)
&lt;https://github.com/litestar-org/polyfactory/pull/636&gt;</code>_</li>
<li>(<code>da6ad4d
&lt;https://github.com/litestar-org/polyfactory/commit/da6ad4d213aec4447e9b3b257ab5fed392f445ae&gt;</code><em>)
- Ignore dataclass types in pydantic field parsing (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/660">#660</a>)
by <code>@adhtruong &lt;https://github.com/adhtruong&gt;</code></em> in
<code>[#660](litestar-org/polyfactory#660)
&lt;https://github.com/litestar-org/polyfactory/pull/660&gt;</code>_</li>
</ul>
<p>Documentation

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</p>
<ul>
<li>(<code>3c1e68f
&lt;https://github.com/litestar-org/polyfactory/commit/3c1e68ffbfa59d0ed9b9cc41d9b9a17654b841e4&gt;</code><em>)
- Add nisemenov as a contributor for code, and doc (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/633">#633</a>)
by <code>@allcontributors[bot]
&lt;https://github.com/allcontributors[bot]&gt;</code></em> in
<code>[#633](litestar-org/polyfactory#633)
&lt;https://github.com/litestar-org/polyfactory/pull/633&gt;</code>_</li>
<li>(<code>beab66c
&lt;https://github.com/litestar-org/polyfactory/commit/beab66cf39a8bf67e3a1ac41cde30ee27ee08be1&gt;</code><em>)
- Add iloveitaly as a contributor for code, and doc (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/662">#662</a>)
by <code>@allcontributors[bot]
&lt;https://github.com/allcontributors[bot]&gt;</code></em> in
<code>[#662](litestar-org/polyfactory#662)
&lt;https://github.com/litestar-org/polyfactory/pull/662&gt;</code>_</li>
</ul>
<p>Features

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</p>
<ul>
<li>(<code>8c1fe02
&lt;https://github.com/litestar-org/polyfactory/commit/8c1fe0293a525fdd20aaadbbf09f8a31dffcdaf8&gt;</code><em>)
- Described an ability to use async data in factory fields; refactored
factories/base and some tests (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/641">#641</a>)
by <code>@nisemenov &lt;https://github.com/nisemenov&gt;</code></em> in
<code>[#641](litestar-org/polyfactory#641)
&lt;https://github.com/litestar-org/polyfactory/pull/641&gt;</code>_</li>
<li>(<code>ba7cd3f
&lt;https://github.com/litestar-org/polyfactory/commit/ba7cd3f382140523d61b35c9ed572c74d8c1ef9f&gt;</code><em>)
- Simplify pytest plugin (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/652">#652</a>)
by <code>@adhtruong &lt;https://github.com/adhtruong&gt;</code></em> in
<code>[#652](litestar-org/polyfactory#652)
&lt;https://github.com/litestar-org/polyfactory/pull/652&gt;</code>_</li>
<li>(<code>b98ae5d
&lt;https://github.com/litestar-org/polyfactory/commit/b98ae5d1c50d24748903e65a8d3b1674f1043f2c&gt;</code><em>)
- Improve create factory typing (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/657">#657</a>)
by <code>@adhtruong &lt;https://github.com/adhtruong&gt;</code></em> in
<code>[#657](litestar-org/polyfactory#657)
&lt;https://github.com/litestar-org/polyfactory/pull/657&gt;</code>_</li>
<li>(<code>33c72e7
&lt;https://github.com/litestar-org/polyfactory/commit/33c72e7bcd1388756a2235e4d75b74fe0de16d27&gt;</code><em>)
- Add_providers to easily add new type provider (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/659">#659</a>)
by <code>@iloveitaly &lt;https://github.com/iloveitaly&gt;</code></em>
in <code>[#659](litestar-org/polyfactory#659)
&lt;https://github.com/litestar-org/polyfactory/pull/659&gt;</code>_</li>
<li>(<code>0b5df15
&lt;https://github.com/litestar-org/polyfactory/commit/0b5df15bd324a7ac2079947dd600e899f2b10798&gt;</code><em>)
- Improve random range (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/653">#653</a>)
by <code>@adhtruong &lt;https://github.com/adhtruong&gt;</code></em> in
<code>[#653](litestar-org/polyfactory#653)
&lt;https://github.com/litestar-org/polyfactory/pull/653&gt;</code>_</li>
</ul>
<p>Miscellaneous Tasks

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</p>
<ul>
<li>(<code>f5cb818
&lt;https://github.com/litestar-org/polyfactory/commit/f5cb818314bf4887f2caab2c3961d1dd886b68cc&gt;</code><em>)
- Bump dawidd6/action-download-artifact from 7 to 9 (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/651">#651</a>)
by <code>@dependabot[bot]
&lt;https://github.com/dependabot[bot]&gt;</code></em> in
<code>[#651](litestar-org/polyfactory#651)
&lt;https://github.com/litestar-org/polyfactory/pull/651&gt;</code>_</li>
<li>(<code>1c56f09
&lt;https://github.com/litestar-org/polyfactory/commit/1c56f09692214cefcfcd3bc29ba9b74fc18a940f&gt;</code><em>)
- Bump codecov/codecov-action from 4 to 5 (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/620">#620</a>)
by <code>@dependabot[bot]
&lt;https://github.com/dependabot[bot]&gt;</code></em> in
<code>[#620](litestar-org/polyfactory#620)
&lt;https://github.com/litestar-org/polyfactory/pull/620&gt;</code>_</li>
<li>(<code>516dd6d
&lt;https://github.com/litestar-org/polyfactory/commit/516dd6d280ee35afda068c7ecaa0d672daf971d1&gt;</code><em>)
- Improve test imports (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/661">#661</a>)
by <code>@adhtruong &lt;https://github.com/adhtruong&gt;</code></em> in
<code>[#661](litestar-org/polyfactory#661)
&lt;https://github.com/litestar-org/polyfactory/pull/661&gt;</code>_</li>
</ul>
<p>Build

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</p>
<ul>
<li>(<code>34182d4
&lt;https://github.com/litestar-org/polyfactory/commit/34182d439d5d5f1f1964a961c028859e3b404851&gt;</code><em>)
- Update dependencies and ignores (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/648">#648</a>)
by <code>@adhtruong &lt;https://github.com/adhtruong&gt;</code></em> in
<code>[#648](litestar-org/polyfactory#648)
&lt;https://github.com/litestar-org/polyfactory/pull/648&gt;</code>_</li>
<li>(<code>396b555
&lt;https://github.com/litestar-org/polyfactory/commit/396b5559ec2a2bbf7818dd15a75b556c18849183&gt;</code><em>)
- Update pyright (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/665">#665</a>)
by <code>@adhtruong &lt;https://github.com/adhtruong&gt;</code></em> in
<code>[#665](litestar-org/polyfactory#665)
&lt;https://github.com/litestar-org/polyfactory/pull/665&gt;</code>_</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/litestar-org/polyfactory/commit/0facd26ec2e8915e1769e90ffb55ccccd60aadc5"><code>0facd26</code></a>
chore: prep 2.20.0 release (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/669">#669</a>)</li>
<li><a
href="https://github.com/litestar-org/polyfactory/commit/396b5559ec2a2bbf7818dd15a75b556c18849183"><code>396b555</code></a>
build: update pyright (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/665">#665</a>)</li>
<li><a
href="https://github.com/litestar-org/polyfactory/commit/beab66cf39a8bf67e3a1ac41cde30ee27ee08be1"><code>beab66c</code></a>
docs: add iloveitaly as a contributor for code, and doc (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/662">#662</a>)</li>
<li><a
href="https://github.com/litestar-org/polyfactory/commit/0b5df15bd324a7ac2079947dd600e899f2b10798"><code>0b5df15</code></a>
feat: improve random range (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/653">#653</a>)</li>
<li><a
href="https://github.com/litestar-org/polyfactory/commit/33c72e7bcd1388756a2235e4d75b74fe0de16d27"><code>33c72e7</code></a>
feat: add_providers to easily add new type provider (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/659">#659</a>)</li>
<li><a
href="https://github.com/litestar-org/polyfactory/commit/516dd6d280ee35afda068c7ecaa0d672daf971d1"><code>516dd6d</code></a>
chore: improve test imports (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/661">#661</a>)</li>
<li><a
href="https://github.com/litestar-org/polyfactory/commit/b98ae5d1c50d24748903e65a8d3b1674f1043f2c"><code>b98ae5d</code></a>
feat: improve create factory typing (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/657">#657</a>)</li>
<li><a
href="https://github.com/litestar-org/polyfactory/commit/da6ad4d213aec4447e9b3b257ab5fed392f445ae"><code>da6ad4d</code></a>
fix: ignore dataclass types in pydantic field parsing (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/660">#660</a>)</li>
<li><a
href="https://github.com/litestar-org/polyfactory/commit/ba7cd3f382140523d61b35c9ed572c74d8c1ef9f"><code>ba7cd3f</code></a>
feat: simplify pytest plugin (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/652">#652</a>)</li>
<li><a
href="https://github.com/litestar-org/polyfactory/commit/1c56f09692214cefcfcd3bc29ba9b74fc18a940f"><code>1c56f09</code></a>
chore(deps): bump codecov/codecov-action from 4 to 5 (<a
href="https://redirect.github.com/litestar-org/polyfactory/issues/620">#620</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/litestar-org/polyfactory/compare/v2.19.0...v2.20.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=polyfactory&package-manager=pip&previous-version=2.19.0&new-version=2.20.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants