Polyfactory and typing #447
Replies: 2 comments
-
@guillaume-alliander I'm so sorry, but I had missed this in my notifications. I'm not sure if what you're trying to achieve is possible, but I'll have to look into a bit to be really sure. However, using it in this way (as a classmethod), you'll see a performance hit if you're creating a lot of instances since each time a new factory would be created which in turn means the model has to be parsed repeatedly. |
Beta Was this translation helpful? Give feedback.
-
Thanks @guacs , I had not thought about the factory in the class method. This does not matter too much for me (it is only inside unit tests), but that is a good point I will look into. I am aware that what I am trying to do (typing Optional) sounds quite tricky, that's why I am asking the expert :) Thanks for looking! |
Beta Was this translation helpful? Give feedback.
-
I am trying to have proper typing with polyfactory (python 3.12, pydantic 2, pyright)
This is mostly correct (I have autocompletion of the Child parameters) but:
type: ignore
inside my Factorio class, Expected when looking at the signature, but I cannot find a better one. At runtime, this works perfectly.Child.generate_test_instance()
complains thatparam
is mandatory. It is according to theChild
spec, but because polyfactory fills up the parameters, it is actually not mandatory. Is there a way to fix this, as in having auto completion, an error if giving a wrong param, but no error if no params are given? In short, the parameters should be seen as optional.Beta Was this translation helpful? Give feedback.
All reactions