NiklasRosenstein / pydoc-markdown

Create Python API documentation in Markdown format.
http://niklasrosenstein.github.io/pydoc-markdown/
Other
460 stars 105 forks source link

"ForwardRef cannot be parameterized." #292

Closed szymon-piechowicz-wandb closed 1 year ago

szymon-piechowicz-wandb commented 1 year ago

Environment

Describe the bug

databind upgrade broke the hugo renderer:

$ pydoc-markdown --bootstrap hugo
created pydoc-markdown.yml
$ pydoc-markdown
Traceback (most recent call last):
  File "/Users/szymon/.pyenv/versions/venv/bin/pydoc-markdown", line 8, in <module>
    sys.exit(cli())
  File ".../lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File ".../lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File ".../lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File ".../lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File ".../lib/python3.9/site-packages/pydoc_markdown/main.py", line 371, in cli
    pydocmd = session.load()
  File ".../lib/python3.9/site-packages/pydoc_markdown/main.py", line 117, in load
    config.load_config(self.config)
  File ".../lib/python3.9/site-packages/pydoc_markdown/__init__.py", line 113, in load_config
    result = databind.json.load(
  File ".../lib/python3.9/site-packages/databind/json/__init__.py", line 67, in load
    return get_object_mapper().deserialize(value, type_, filename, settings)
  File ".../lib/python3.9/site-packages/databind/core/mapper.py", line 104, in deserialize
    self.convert(Direction.DESERIALIZE, value, datatype, Location(filename, None, None), settings),
  File ".../lib/python3.9/site-packages/databind/core/mapper.py", line 76, in convert
    return context.convert()
  File ".../lib/python3.9/site-packages/databind/core/context.py", line 123, in convert
    return self.convert_func(self)
  File ".../lib/python3.9/site-packages/databind/core/converter.py", line 80, in convert
    return converter.convert(ctx)
  File ".../lib/python3.9/site-packages/databind/core/converter.py", line 80, in convert
    return converter.convert(ctx)
  File ".../lib/python3.9/site-packages/databind/core/converter.py", line 45, in convert
    return self.deserialize(ctx)
  File ".../lib/python3.9/site-packages/databind/json/converters.py", line 561, in deserialize
    value = ctx.spawn(container[field_name], field.datatype, field_name).convert()
  File ".../lib/python3.9/site-packages/databind/core/context.py", line 123, in convert
    return self.convert_func(self)
  File ".../lib/python3.9/site-packages/databind/core/converter.py", line 80, in convert
    return converter.convert(ctx)
  File ".../lib/python3.9/site-packages/databind/core/converter.py", line 80, in convert
    return converter.convert(ctx)
  File ".../lib/python3.9/site-packages/databind/json/converters.py", line 789, in convert
    result = child_context.convert()
  File ".../lib/python3.9/site-packages/databind/core/context.py", line 123, in convert
    return self.convert_func(self)
  File ".../lib/python3.9/site-packages/databind/core/converter.py", line 80, in convert
    return converter.convert(ctx)
  File ".../lib/python3.9/site-packages/databind/core/converter.py", line 80, in convert
    return converter.convert(ctx)
  File ".../lib/python3.9/site-packages/databind/core/converter.py", line 45, in convert
    return self.deserialize(ctx)
  File ".../lib/python3.9/site-packages/databind/json/converters.py", line 561, in deserialize
    value = ctx.spawn(container[field_name], field.datatype, field_name).convert()
  File ".../lib/python3.9/site-packages/databind/core/context.py", line 123, in convert
    return self.convert_func(self)
  File ".../lib/python3.9/site-packages/databind/core/converter.py", line 80, in convert
    return converter.convert(ctx)
  File ".../lib/python3.9/site-packages/databind/core/converter.py", line 80, in convert
    return converter.convert(ctx)
  File ".../lib/python3.9/site-packages/databind/json/converters.py", line 129, in convert
    values = list(values)
  File ".../lib/python3.9/site-packages/databind/json/converters.py", line 115, in <genexpr>
    ctx.spawn(val, item_type, idx).convert()
  File ".../lib/python3.9/site-packages/databind/core/context.py", line 123, in convert
    return self.convert_func(self)
  File ".../lib/python3.9/site-packages/databind/core/converter.py", line 80, in convert
    return converter.convert(ctx)
  File ".../lib/python3.9/site-packages/databind/core/converter.py", line 80, in convert
    return converter.convert(ctx)
  File ".../lib/python3.9/site-packages/databind/core/converter.py", line 45, in convert
    return self.deserialize(ctx)
  File ".../lib/python3.9/site-packages/databind/json/converters.py", line 506, in deserialize
    schema = self._get_schema(ctx)
  File ".../lib/python3.9/site-packages/databind/json/converters.py", line 430, in _get_schema
    return self.convert_to_schema(datatype)
  File ".../lib/python3.9/site-packages/databind/core/schema.py", line 125, in convert_to_schema
    schema = convert_dataclass_to_schema(hint)
  File ".../lib/python3.9/site-packages/databind/core/schema.py", line 249, in convert_dataclass_to_schema
    base_hint = TypeHint(base).parameterize(parameter_map)
  File ".../lib/python3.9/site-packages/typeapi/typehint.py", line 260, in parameterize
    return super().parameterize(parameter_map)
  File ".../lib/python3.9/site-packages/typeapi/typehint.py", line 204, in parameterize
    args = tuple(TypeHint(x).parameterize(parameter_map).hint for x in self.args)
  File ".../lib/python3.9/site-packages/typeapi/typehint.py", line 204, in <genexpr>
    args = tuple(TypeHint(x).parameterize(parameter_map).hint for x in self.args)
  File ".../lib/python3.9/site-packages/typeapi/typehint.py", line 376, in parameterize
    raise RuntimeError(
RuntimeError: ForwardRef cannot be parameterized. Ensure that your type hint is fully evaluated before parameterization.

Expected behavior

The hugo renderer should work.

NiklasRosenstein commented 1 year ago

Thanks for reporting this! It's a bug in databind. The unit tests of Pydoc-Markdown do not cover the deserialization sufficiently, which I'll address with the fix. In the meantime, you should be good when downgrading to Pydoc-Markdown 4.7.0.

NiklasRosenstein commented 1 year ago

Fixed in #294 and v4.8.1 🚀