Skip to content

TypeError: ForwardRef._evaluate() got an unexpected keyword argument 'type_params' #11230

@masenf

Description

@masenf

Initial Checks

  • I have searched GitHub for a duplicate issue and I'm sure this is something new
  • I have searched Google & StackOverflow for a solution and couldn't find anything
  • I have read and followed the docs and still think this is a bug
  • I am confident that the issue is with pydantic (not my code, or another library in the ecosystem like FastAPI or mypy)

Description

On python 3.12.0 - 3.12.3, the recently released pydantic-1.10.20 doesn't work with forward ref type annotations.

Downgrading to pydantic-1.10.19 does not throw the exception.

Potentially related to #9609

Example Code

from pydantic import BaseModel


class Schema(BaseModel):
    test: "Foo"

Foo = str

"""
Traceback (most recent call last):
  File "//ts.py", line 4, in <module>
    class Schema(BaseModel):
  File "/usr/local/lib/python3.12/site-packages/pydantic/main.py", line 292, in __new__
    cls.__try_update_forward_refs__()
  File "/usr/local/lib/python3.12/site-packages/pydantic/main.py", line 813, in __try_update_forward_refs__
    update_model_forward_refs(cls, cls.__fields__.values(), cls.__config__.json_encoders, localns, (NameError,))
  File "/usr/local/lib/python3.12/site-packages/pydantic/typing.py", line 566, in update_model_forward_refs
    update_field_forward_refs(f, globalns=globalns, localns=localns)
  File "/usr/local/lib/python3.12/site-packages/pydantic/typing.py", line 532, in update_field_forward_refs
    field.type_ = evaluate_forwardref(field.type_, globalns, localns or None)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pydantic/typing.py", line 75, in evaluate_forwardref
    return cast(Any, type_)._evaluate(globalns, localns, type_params=(), recursive_guard=set())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: ForwardRef._evaluate() got an unexpected keyword argument 'type_params'
"""

Python, Pydantic & OS Version

python==3.12.3
pydantic==1.10.20
debian 12 (python:3.12.3 docker image)

Affected Components

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug V1Bug related to Pydantic V1.XpendingIs unconfirmed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions