Closed danielkza closed 3 weeks ago
Hi @danielkza, I see from your traceback that you're using python 3.12, that's most likely the issue. I'll try to add it to the test suite so that we can verify this issue and fix it.
Python 3.12 works fine without the future annotations though! if that makes any difference. We prob need to resolve forwardrefs, I think there is something for it somewhere in pydantic: https://github.com/pydantic/pydantic/blob/b1bb24e8b7687e5891bce33f551625ac01b74b66/pydantic/v1/typing.py#L63
or maybe even take it up a layer further, and try to reuse some of the type evaluation logic if possible.
Thanks for the inputs, this is next in line to be solved since it's a bit critical. The link you sent is a good example of why I really never bothered with Python typing that much, so far 🙃 It's such a mess. Let's see what can be done though!
Just a few comments on this: I looked into this and the rabbit hole is deeper than I thought. As you know, the problem is basically linked to the lack of actual type annotations when using the __future__
import, which is the intended behavior for postponed annotations.
This is however a huge issue for a library based on type annotations, as you can imagine. It is true however that pydantic just "works" with it, the only hiccup I found was in the initial manual wrapping I was carrying out.
I shoud have patched it (at least for the moment) by resolving types via typing.get_type_hints
before inspecting functions, from there on it seems to be working fine since pydantic takes the lead. However there are some caveats linked to scopes, but I fear there's nothing I can do in that case, even pydantic has limitations there (see https://github.com/pydantic/pydantic/discussions/4521).
Describe the bug
To Reproduce Add
from __future__ import annotations
to the top of a Python file and use argdanticExpected behavior No crash
Actual behaviour