Skip to content

bug: TypeError: Unable to evaluate type annotation with 1.14.x #241

Closed

Description

@davidmezzetti

Hello,

First off, thank you for your efforts in open source. I've been a long time user of this library with txtai and have never had issues. So while I'm reporting an issue now, just wanted to first say I appreciate all the hard work.

With 1.14.x, I'm getting a doc build error as follows with Python 3.9.

  File "python3.9/site-packages/mkdocstrings_handlers/python/__init__.py", line 3, in <module>
    from mkdocstrings_handlers.python.handler import get_handler
  File "python3.9/site-packages/mkdocstrings_handlers/python/handler.py", line 30, in <module>
    from mkdocstrings_handlers.python.config import PythonConfig, PythonOptions
  File "python3.9/site-packages/mkdocstrings_handlers/python/config.py", line 254, in <module>
    class AutoStyleOptions:
  File "python3.9/site-packages/pydantic/dataclasses.py", line 276, in create_dataclass
    _pydantic_dataclasses.complete_dataclass(cls, config_wrapper, raise_errors=False)
  File "python3.9/site-packages/pydantic/_internal/_dataclasses.py", line 128, in complete_dataclass
    set_dataclass_fields(cls, ns_resolver, config_wrapper=config_wrapper)
  File "python3.9/site-packages/pydantic/_internal/_dataclasses.py", line 78, in set_dataclass_fields
    fields = collect_dataclass_fields(
  File "python3.9/site-packages/pydantic/_internal/_fields.py", line 322, in collect_dataclass_fields
    ann_type, _ = _typing_extra.try_eval_type(dataclass_field.type, globalns, localns)
  File "python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 558, in try_eval_type
    return eval_type_backport(value, globalns, localns), True
  File "python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 609, in eval_type_backport
    return _eval_type_backport(value, globalns, localns, type_params)
  File "python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 641, in _eval_type_backport
    raise TypeError(
TypeError: Unable to evaluate type annotation "Annotated[str | None, Field(group='docstrings', parent='docstring_options', description='The default docstring style to use if no other style is detected.')]". If you are making use of the new typing syntax (unions using `|` since Python 3.10 or builtins subscripting since Python 3.9), you should either replace the use of new syntax with the existing `typing` constructs or install the `eval_type_backport` package.

Installing the eval_type_backport package fixes the issue. But given that it didn't happen before 1.14.x, I wanted to let you know. If this is expected, please feel free to close the issue.

Activity

  1. added
    unconfirmed
    on Feb 4, 2025
  2. pawamoy commented on Feb 4, 2025

    @pawamoy
    Member

    Hi @davidmezzetti, thank you for the report, and for the kind words 💓 ! Could you tell me what version of Pydantic you have installed?

  3. davidmezzetti commented on Feb 4, 2025

    @davidmezzetti
    Author

    I appreciate the rapid response. Here is what I have:

    pydantic==2.10.6
    pydantic-settings==2.7.1
    pydantic_core==2.27.2
    
  4. pawamoy commented on Feb 4, 2025

    @pawamoy
    Member

    Thank you! OK I had eval-type-backport installed locally so didn't catch this behavior. Let me add this dependency for Python 3.9 🙂 EDIT: hmm, actually no, it wouldn't be of any help to have eval-type-backport if we don't have pydantic installed in the first place. I'll instead add a check in order to deactivate Pydantic use if eval-type-backport is not available on Python 3.9.

  5. davidmezzetti commented on Feb 4, 2025

    @davidmezzetti
    Author

    Sounds good, whatever is easier for you and makes sense for the project. I appreciate the quick dialogue.

  6. added
    bug
    and removed
    unconfirmed
    on Feb 4, 2025
  7. pawamoy commented on Feb 4, 2025

    @pawamoy
    Member

    v1.14.4 released, thanks again!

  8. davidmezzetti commented on Feb 4, 2025

    @davidmezzetti
    Author

    Wow, thank you for the rapid response. Now that's service!

  9. davidmezzetti commented on Feb 4, 2025

    @davidmezzetti
    Author

    And I'll confirm the issue is fixed for my use case!

  10. pawamoy commented on Feb 4, 2025

    @pawamoy
    Member

    Awesome, thanks for confirming 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions