zwang123 / sphinx-autodoc-defaultargs

Automatic generation of default arguments for the Sphinx autodoc extension.
MIT License
4 stars 0 forks source link

UnboundLocalError: local variable 'i' referenced before assignment #1

Closed erwanp closed 3 years ago

erwanp commented 3 years ago

Hello @zwang123 , thank you for this package !

We tried to use it at https://github.com/radis/radis , but the Pypi version breaks our Doc build https://github.com/radis/radis/issues/223

Errror :

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/radis/envs/develop/lib/python3.6/site-packages/sphinx/events.py", line 111, in emit
    results.append(listener.handler(self.app, *args))
  File "/home/docs/checkouts/readthedocs.org/user_builds/radis/envs/develop/lib/python3.6/site-packages/sphinx_autodoc_defaultargs.py", line 325, in process_docstring
    match_field(lines, searchfor, include_blank=app.config.
  File "/home/docs/checkouts/readthedocs.org/user_builds/radis/envs/develop/lib/python3.6/site-packages/sphinx_autodoc_defaultargs.py", line 121, in match_field
    starting_line_index = i + 1  # Set no matter found or not
UnboundLocalError: local variable 'i' referenced before assignment

I looked at your source code. I understand it's because "i" was added only in your latest commit https://github.com/zwang123/sphinx-autodoc-defaultargs/commit/3e62ef93699a0824298363e81c4989243c81e8a3#diff-43a467e84fa7a1f1ea24d2ec7c796eb742720b3f54bc75317fa42d77a2a78d0bR87

But this version does not seem to be deployed on PyPi. Can you upgrade the package ?

zwang123 commented 3 years ago

@erwanp Thank you very much for mentioning this. I am appreciated for your usage and mentioning the issue. I have released the latest version and this bug should be fixed. Could you please confirm that?

erwanp commented 3 years ago

Hello ! The new version installs and runs properly, thank you for updating it ! You can close this issue.

However, I did not manage to generate the default arguments. I will retry, but would be nice if you could point us to a package & readthedocs that actually implement it ?

zwang123 commented 3 years ago

Thank you. I have read the conf.py in your repository. I am currently using this package in my private repositories and it works well. As explained in the README.md, you need this in conf.py.

rst_prolog = """
.. |default| raw:: html

    <div class="default-value-section">""" + \
    ' <span class="default-value-label">Default:</span>'

Please feel free to report any bugs after applying this.

erwanp commented 3 years ago

Thank you ! That's what I think we already have :

https://github.com/radis/radis/blob/c7616b0856bd8582e01c1990c535f9aeaf9ad8ed/docs/conf.py#L313

rst_prolog = """
.. |default| raw:: html

    <div class="default-value-section">""" + \
    ' <span class="default-value-label">Default:</span>'
zwang123 commented 3 years ago

I see. I have realized you used Default ... . format in your docstrings. You might want to either set docstring_default_arg_flags as [('(Default: ', ')'), ('Default ', '.')], or to change your existing docstring formats for default arguments with less conflicting possibilities. Please do the former one with caution as any existing Default ... . will be recognized as default arguments and converted even if it is in the middle of explanatory texts.

Anyway, I am closing this issue as the original issue is already resolved. Could you please open a new issue with more details including some of the texts after the napoleon and sphinx_autodoc_defaultargs processing as well as what you had seen in the compiled web page?