Closed Guibod closed 1 month ago
The problem is reproduced in this repository: https://github.com/Guibod/pydantic-settings-bug-298
The problem occurs with python 3.8 and 3.9, and only under the influence of injector
.
It’s ok to close the bug if you consider that it is not bound to your code. Nonetheless, the PEP-484 trick worked, but PEP-604 seems not to work.
From my discoveries, the issue is bound to the BaseSettings
constructor as inferred by injector
.
If i define a custom factory:
class Configuration(Module):
def configure(self, binder: Binder):
binder.bind(MainSettings, scope=SingletonScope, to=lambda: MainSettings())
Everything runs smoothly.
I guess you can try to dig in the support for cls.__new__(cls)
pattern in your tests.
Thanks @Guibod for reporting this and preparing the test project.
As you mentioned this is not a problem of pydantic-settings
. We want to keep the pipe-based field type because we are happy with that.
ok, then i’ll push this to injector
.
I’ve stumbled on an issue on my tox tests will running my tests today. My project relies on injector which relies on typing to infer variables to be injected.
There was also another instance of error about Generics, this was the improper Unions.
I managed to make everything to pass when I updated all occurences of piped type definitions to proper
Optional
andUnion
The bug was detected on 3.9.16, then reproduced in 3.9.19
The stackstrace
I’ve cut everything related to my own project. But it seems that
injector
requeststyping
(installed via brew on my mac) to explore theBaseSettings
class, and fail. I’ll try to run a minimal project to demonstrate the issue using onlyget_type_hints
onBaseSettings
class.