Checks
Bug
Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":
pydantic version: 1.8.1
pydantic compiled: False
install path: /nix/store/1f6nk37c7df54cm8b3rlnn6pidaa3mrp-python3.8-pydantic-1.8.1/lib/python3.8/site-packages/pydantic
python version: 3.8.8 (default, Feb 19 2021, 11:04:50) [GCC 9.3.0]
platform: Linux-5.4.114-x86_64-with
optional deps. installed: ['typing-extensions']
Here's the smallest program I could come up with that fails under from __future__ import annotations but works without it:
from __future__ import annotations
from pydantic import BaseModel, PositiveInt
from typing import NamedTuple
class Tup(NamedTuple):
v: PositiveInt
class Mod(BaseModel):
t: Tup
print(Mod.parse_obj({"t": [3]}))
The call to parse_obj raises this exception: pydantic.errors.ConfigError: field "v" not yet prepared so type is still a ForwardRef, you might need to call Tup.update_forward_refs(). But there is no update_forward_refs on NamedTuple instances.
Just using a base int in the NamedTuple doesn't exhibit the same problem, but of course it also doesn't check the constraints I want.
My current workaround is to just not use from __future__ import annotations in the module where I declare and use the NamedTuple, but I was hoping to use the new style consistently throughout the project.
Checks
Bug
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())":Here's the smallest program I could come up with that fails under
from __future__ import annotationsbut works without it:The call to
parse_objraises this exception:pydantic.errors.ConfigError: field "v" not yet prepared so type is still a ForwardRef, you might need to call Tup.update_forward_refs().But there is noupdate_forward_refsonNamedTupleinstances.Just using a base
intin theNamedTupledoesn't exhibit the same problem, but of course it also doesn't check the constraints I want.My current workaround is to just not use
from __future__ import annotationsin the module where I declare and use theNamedTuple, but I was hoping to use the new style consistently throughout the project.