Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the cause of an unexpected indentation warning when generating code documentation?

Tags:

The documentation code with the problem is at the beginning of a method:

"""
Gtk.EventBox::button-release-event signal handler.
:param widget: The clicked widget (The Gtk.EventBox).
:param event: Gdk.EventButton object with information regarding
       the event.
:param user_data: The Gtk.LinkButton that should be opened when
       the Gtk.EventBox is clicked.
:return: None
"""

The warnings are:

C:/msys64/home/hope/python+gtk/test/main.py:docstring of main.Builder.advertisem
ent_clicked:4: WARNING: Unexpected indentation.
C:/msys64/home/hope/python+gtk/test/main.py:docstring of main.Builder.advertisem
ent_clicked:5: WARNING: Block quote ends without a blank line; unexpected uninde
nt.

What can be done to remove these warnings and their cause(s)?

like image 722
silviubogan Avatar asked Aug 25 '17 11:08

silviubogan


People also ask

How do I get rid of unexpected indent?

“IndentationError: unexpected indent” is raised when you indent a line of code too many times. To solve this error, make sure all of your code uses consistent indentation and that there are no unnecessary indents.

What is unexpected indent error?

This error occurs when a statement is unnecessarily indented or its indentation does not match the indentation of former statements in the same block. Python not only insists on indentation, it insists on consistent indentation .

What causes indentation error in Python?

The cause of Indentation Error in Python Since python makes use of procedural language, if you miss out on adding tabs or spaces between your lines of code, then you will most likely experience this error.


2 Answers

Just add a blank line after the summary description of the method, before the description of the parameters:

"""
Gtk.EventBox::button-release-event signal handler.

:param widget: The clicked widget (The Gtk.EventBox).
:param event: Gdk.EventButton object with information regarding
       the event.
:param user_data: The Gtk.LinkButton that should be opened when
       the Gtk.EventBox is clicked.
:return: None
"""

Here you can find this advice:

If you get a Sphinx build error that says “Unexpected indentation,” it is probably because Sphinx is expecting a blank line, such as after a literal text block. Your line may have wrapped and confused Sphinx. In this case, try pulling the text up to the previous line even if it extends out past the margin of your window. Or, you could press Enter to go to the next line, but be sure to indent the text on the new line.

like image 85
silviubogan Avatar answered Oct 21 '22 11:10

silviubogan


Maybe this will help somebody who stumbles upon this question - in my case I was getting a bunch of warnings that were because I was using Google style docstrings. Just add "sphinx.ext.napoleon" to the extensions list in conf.py and the warnings should go away.

like image 43
jerry_ Avatar answered Oct 21 '22 13:10

jerry_