Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
davidmezzetti opened this issue Feb 4, 2025 · 8 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@davidmezzetti
Copy link

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.

@davidmezzetti davidmezzetti added the unconfirmed This bug was not reproduced yet label Feb 4, 2025
@pawamoy
Copy link
Member

pawamoy commented Feb 4, 2025

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

@davidmezzetti
Copy link
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

@pawamoy
Copy link
Member

pawamoy commented Feb 4, 2025

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.

@davidmezzetti
Copy link
Author

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

@pawamoy pawamoy added bug Something isn't working and removed unconfirmed This bug was not reproduced yet labels Feb 4, 2025
pawamoy added a commit that referenced this issue Feb 4, 2025
…ort` is not available (for modern typing syntax support)

Issue-241: #241
@pawamoy
Copy link
Member

pawamoy commented Feb 4, 2025

v1.14.4 released, thanks again!

@pawamoy pawamoy closed this as completed Feb 4, 2025
@davidmezzetti
Copy link
Author

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

@davidmezzetti
Copy link
Author

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

@pawamoy
Copy link
Member

pawamoy commented Feb 4, 2025

Awesome, thanks for confirming 🙏

viktorlashchuk added a commit to viktorlashchuk/mkdocstrings-python that referenced this issue Feb 24, 2025
…ort` is not available (for modern typing syntax support)

Issue-241: mkdocstrings/python#241
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants