Trying to use polyfactory with a model with a typing.Any field, I cannot seem to cover it in the get_provider_map. Using object instead of Any works as a workaround, but does not feel right.
from typing import Any
from polyfactory.factories.pydantic_factory import ModelFactory
from pydantic import BaseModel
class WeirdModel(BaseModel):
any: Any
obj: object
class Factorio(ModelFactory[WeirdModel]):
@classmethod
def get_provider_map(cls) -> dict[type, Any]:
providers_map = super().get_provider_map()
return {
**providers_map,
Any: lambda: "this does not work",
object: lambda: "this works as workaround",
}
print(Factorio().build())
# prints: any='<a random string>' obj='this works as workaround'
# I would expect "this does not work" for any
Steps to reproduce
Just run the above script (tested with python 3.12) for instance on the command line.
Screenshots
"In the format of: ![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"
Description
Trying to use polyfactory with a model with a
typing.Any
field, I cannot seem to cover it in theget_provider_map
. Usingobject
instead ofAny
works as a workaround, but does not feel right.Related to https://github.com/litestar-org/polyfactory/discussions/515
URL to code causing the issue
No response
MCVE
Steps to reproduce
Screenshots
"In the format of:
![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)
"Logs
No response
Release Version
polyfactory==2.15.0 pydantic==2.6.4 pydantic_core==2.16.3
Platform