mitmproxy / mitmproxy/pdoc

pdoc is raising exception if using in project using pydantic v1

Open
#864 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
2.5k
Forks
228
PR merge metrics
No merged PRs in 30d

Description

I have an Object using pydantic v1

e.g.

class Model(BaseModel):
    """Docstring"""
    value: int

Used pydantic 1.10.24 and pdoc 16.0.0

When I try to generate documentation I get following error:

python -m pdoc -d google

Traceback (most recent call last):
File "\lib\site-packages\pdoc\web.py", line 84, in handle_request
out = render.html_module(
File "C:\Program Files\Python310\lib\contextlib.py", line 79, in inner
return func(*args, **kwds)
File "\lib\site-packages\pdoc\render.py", line 106, in html_module
return env.get_template("module.html.jinja2").render(
File "\lib\site-packages\jinja2\environment.py", line 1295, in render
self.environment.handle_exception()
File "\lib\site-packages\jinja2\environment.py", line 942, in handle_exception
raise rewrite_traceback_stack(source=source)
File "\lib\site-packages\pdoc\templates\default\module.html.jinja2", line 315, in top-level template code
{%- if loop.nextitem -%}
File "\lib\site-packages\pdoc\templates\default\frame.html.jinja2", line 36, in top-level template code
{% block body %}
File "\lib\site-packages\pdoc\templates\default\frame.html.jinja2", line 42, in block 'body'
{% block content %}{% endblock %}
File "\lib\site-packages\pdoc\templates\default\module.html.jinja2", line 80, in block 'content'
{% block module_info %}
File "\lib\site-packages\pdoc\templates\default\module.html.jinja2", line 95, in block 'module_info'
{{ docstring(module) }}
File "\lib\site-packages\jinja2\runtime.py", line 784, in _invoke
rv = self._func(*arguments)
File "\lib\site-packages\pdoc\templates\default\module.html.jinja2", line 212, in template

{{ var.docstring | replace("@public", "") | to_markdown | to_html | linkify(namespace=var.qualname, shorten=False) }}
File "\lib\site-packages\pdoc\render_helpers.py", line 405, in linkify
re.sub(
File "C:\Program Files\Python310\lib\re.py", line 209, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "\lib\site-packages\pdoc\render_helpers.py", line 371, in linkify_repl
if doc := context["all_modules"].get(module_name, {}).get(qualname):
File "\lib\site-packages\pdoc\doc.py", line 387, in get
return h.get(tail)
File "\lib\site-packages\pdoc\doc.py", line 390, in get
return self.members.get(identifier, None)
File "C:\Program Files\Python310\lib\functools.py", line 981, in get
val = self.func(instance)
File "\lib\site-packages\pdoc\doc.py", line 330, in members
if _doc := _pydantic.get_field_docstring(cast(type, self.obj), name):
File "\lib\site-packages\pdoc_pydantic.py", line 52, in get_field_docstring
if field := parent.pydantic_fields.get(field_name, None):
AttributeError: type object 'BaseModel' has no attribute 'pydantic_fields'

The request is mainly to avoid this exception to get the standard documentation as with pdoc 15.x nevertheless it would be great to get also support for v1 :-)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with pdoc/_pydantic.py, especially get_field_docstring, where the traceback shows the Pydantic v2-only attribute access. Reproduce with pydantic 1.10.24 using python -m pdoc -d google ; done means documentation generation no longer raises the reported exception and retains standard pdoc 15.x behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.