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.
Related to https://github.com/litestar-org/polyfactory/discussions/515
No response
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
Just run the above script (tested with python 3.12) for instance on the command line.
"In the format of: ![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)
"
No response
polyfactory==2.15.0
pydantic==2.6.4
pydantic_core==2.16.3
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too