python-betterproto icon indicating copy to clipboard operation
python-betterproto copied to clipboard

Fix documentation

Open AdrienVannson opened this issue 1 year ago • 1 comments

Summary

The documentation of services and methods was not properly added to the generated files. The issue was that ServiceCompiler and ServiceMethodCompiler didn't have access to the value of source_file, unlike the other compilers.

As far as I understand, the field was accessed in the get_comment function. Since it was missing, an AttributeError was raised, but this error was catched by jinja automatically, as in the following example:

from dataclasses import dataclass

from jinja2 import Template

TEMPLATE: str = """
AA
{{ my_class.field }}
BB
{{ my_class.nothing }}
CC
"""

@dataclass
class MyClass:
    field: int

print(Template(TEMPLATE).render(my_class=MyClass(field=42)))

Checklist

  • [X] If code changes were made then they have been tested.
  • [X] This PR fixes an issue.

AdrienVannson avatar Oct 18 '24 09:10 AdrienVannson

To avoid silencing these errors, it is possible to add a parameter undefined=jinja2.StrictUndefined to the jinja2 environment. I didn't add it here since other errors are currently raised, but I think it would be a good thing to do it at some point. Maybe some issues are still hidden by this behavior.

AdrienVannson avatar Oct 18 '24 10:10 AdrienVannson

Thanks!

Gobot1234 avatar Oct 22 '24 18:10 Gobot1234