mansenfranzen / autodoc_pydantic

Seamlessly integrate pydantic models in your Sphinx documentation.
MIT License
159 stars 27 forks source link

ForwardRef.__init__() got an unexpected keyword argument 'is_class' #185

Closed sanjacob closed 10 months ago

sanjacob commented 1 year ago

Greetings,

Trying out your project for the first time, and after installing and configuring I get the following error when building with make html.

Using version 2.0.1 and pydantic 2.1.1

Running Sphinx v7.2.6

Exception occurred:
  File "/home/jacob/.local/share/virtualenvs/.../lib/python3.10/site-packages/pydantic/_internal/_typing_extra.py", line 221, in eval_type_lenient
    value = _make_forward_ref(value, is_argument=False, is_class=True)
TypeError: ForwardRef.__init__() got an unexpected keyword argument 'is_class'
The full traceback has been saved in /tmp/sphinx-err-t6cdcfow.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
make: *** [Makefile:20: html] Error 2

I copy the full traceback here:

# Platform:         linux; (Linux-5.10.0-26-amd64-x86_64-with-glibc2.31)
# Sphinx version:   7.2.6
# Python version:   3.10.0 (CPython)
# Docutils version: 0.18.1
# Jinja2 version:   3.1.2
# Pygments version: 2.17.2

# Last messages:

# Loaded extensions:

# Traceback:
Traceback (most recent call last):
  File "/home/jacob/.local/share/virtualenvs/bblearn-7K6zF-Oo/lib/python3.10/site-packages/sphinx/cmd/build.py", line 293, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
  File "/home/jacob/.local/share/virtualenvs/bblearn-7K6zF-Oo/lib/python3.10/site-packages/sphinx/application.py", line 233, in __init__
    self.setup_extension(extension)
  File "/home/jacob/.local/share/virtualenvs/bblearn-7K6zF-Oo/lib/python3.10/site-packages/sphinx/application.py", line 406, in setup_extension
    self.registry.load_extension(self, extname)
  File "/home/jacob/.local/share/virtualenvs/bblearn-7K6zF-Oo/lib/python3.10/site-packages/sphinx/registry.py", line 447, in load_extension
    mod = import_module(extname)
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/jacob/.local/share/virtualenvs/bblearn-7K6zF-Oo/lib/python3.10/site-packages/sphinxcontrib/autodoc_pydantic/__init__.py", line 16, in <module>
    from sphinxcontrib.autodoc_pydantic.directives.autodocumenters import (
  File "/home/jacob/.local/share/virtualenvs/bblearn-7K6zF-Oo/lib/python3.10/site-packages/sphinxcontrib/autodoc_pydantic/directives/autodocumenters.py", line 11, in <module>
    from pydantic_settings import BaseSettings
  File "/home/jacob/.local/share/virtualenvs/bblearn-7K6zF-Oo/lib/python3.10/site-packages/pydantic_settings/__init__.py", line 1, in <module>
    from .main import BaseSettings, SettingsConfigDict
  File "/home/jacob/.local/share/virtualenvs/bblearn-7K6zF-Oo/lib/python3.10/site-packages/pydantic_settings/main.py", line 40, in <module>
    class BaseSettings(BaseModel):
  File "/home/jacob/.local/share/virtualenvs/bblearn-7K6zF-Oo/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 172, in __new__
    set_model_fields(cls, bases, config_wrapper, types_namespace)
  File "/home/jacob/.local/share/virtualenvs/bblearn-7K6zF-Oo/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 400, in set_model_fields
    fields, class_vars = collect_model_fields(cls, bases, config_wrapper, types_namespace, typevars_map=typevars_map)
  File "/home/jacob/.local/share/virtualenvs/bblearn-7K6zF-Oo/lib/python3.10/site-packages/pydantic/_internal/_fields.py", line 98, in collect_model_fields
    type_hints = get_cls_type_hints_lenient(cls, types_namespace)
  File "/home/jacob/.local/share/virtualenvs/bblearn-7K6zF-Oo/lib/python3.10/site-packages/pydantic/_internal/_typing_extra.py", line 212, in get_cls_type_hints_lenient
    hints[name] = eval_type_lenient(value, globalns, localns)
  File "/home/jacob/.local/share/virtualenvs/bblearn-7K6zF-Oo/lib/python3.10/site-packages/pydantic/_internal/_typing_extra.py", line 221, in eval_type_lenient
    value = _make_forward_ref(value, is_argument=False, is_class=True)
TypeError: ForwardRef.__init__() got an unexpected keyword argument 'is_class'
mansenfranzen commented 11 months ago

Hi @sanjacob,

thanks for raising the issue! This issue could be very well related to autodoc_pydantic and a API incompatibility with newer pydantic versions. To clarify this, I will require a minimal reproducible example from you. Otherwise I can't help :-(.

Could you provide a simple example showcasing the error? Thanks!

sanjacob commented 11 months ago

I think this is an issue with Python 3.10. I'll check with Python 3.10.11 and give an update.

sanjacob commented 10 months ago

Indeed, this resolved itself upon upgrading the python version