Skip to content

dataclasses.field breaks doc generation #116

@szemate

Description

@szemate

If dataclasses.field is assigned as default value to a field in a class in the module documentation is generated for, doc generation breaks with AttributeError.

E.g. take the following module:

from dataclasses import dataclass, field
from typing import Any, List

@dataclass
class C:
    mylist: List[Any] = field(default_factory=list)

Expected Behavior

Successful doc generation

Actual Behavior

Traceback (most recent call last):
  File "/home/szemate/.local/lib/python3.7/site-packages/pdoc/__init__.py", line 122, in _render_template
    return t.render(**config).strip()
  File "/usr/lib/python3.7/site-packages/mako/template.py", line 476, in render
    return runtime._render(self, self.callable_, args, data)
  File "/usr/lib/python3.7/site-packages/mako/runtime.py", line 883, in _render
    **_kwargs_for_callable(callable_, data)
  File "/usr/lib/python3.7/site-packages/mako/runtime.py", line 920, in _render_context
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
  File "/usr/lib/python3.7/site-packages/mako/runtime.py", line 947, in _exec_template
    callable_(context, *args, **kwargs)
  File "/home/szemate/.local/lib/python3.7/site-packages/pdoc/templates/html.mako", line 394, in render_body
    ${show_module(module)}
  File "/home/szemate/.local/lib/python3.7/site-packages/pdoc/templates/html.mako", line 0, in show_module
    
  File "/home/szemate/.local/lib/python3.7/site-packages/pdoc/templates/html.mako", line 178, in render_show_module
    params = ', '.join(c.params(annotate=show_type_annotations, link=link))
  File "/home/szemate/.local/lib/python3.7/site-packages/pdoc/__init__.py", line 900, in params
    annotate=annotate, link=link, module=self.module)
  File "/home/szemate/.local/lib/python3.7/site-packages/pdoc/__init__.py", line 1137, in _params
    p = safe_default_value(p)
  File "/home/szemate/.local/lib/python3.7/site-packages/pdoc/__init__.py", line 1110, in safe_default_value
    replacement = html.escape(replacement or p.default)
  File "/usr/lib64/python3.7/html/__init__.py", line 19, in escape
    s = s.replace("&", "&") # Must be done first!
AttributeError: '_HAS_DEFAULT_FACTORY_CLASS' object has no attribute 'replace'

Additional info

  • pdoc version: 0.7.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions