Skip to content

Commit

Permalink
fix incorrect line offsets under Python <= 3.7
Browse files Browse the repository at this point in the history
Python 3.8:

```console
$ flake8 --select RST RST216/roles.py
RST216/roles.py:9:1: RST216 Multiple roles in interpreted text (both prefix and suffix present; only one allowed).
```

On Python 3.7 (before this fix) got the line number wrong:

```console
$ flake8 --select RST RST216/roles.py
RST216/roles.py:10:1: RST216 Multiple roles in interpreted text (both prefix and suffix present; only one allowed).
```

Problem dates from #37 (not reliably counting the number of
lines in a docstring), with #38 only a partial fix.
  • Loading branch information
xmo-odoo authored and peterjc committed Dec 9, 2021
1 parent 35c4bfb commit ee0c653
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions flake8_rst_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ def run(self):
start = node.body[0].lineno - 1 # AST value 1 based
except AttributeError:
# On Python 3.7 or older, and must compute start line
start = node.body[0].lineno - len(
ast.get_docstring(node, clean=False).splitlines()
start = (
node.body[0].lineno
- ast.get_docstring(node, clean=False).count("\n")
- 1
)
if isinstance(node, ast.Module) and start > 1:
start -= 1 # Why?
assert (
node.body[0].lineno >= 1 and start >= 0
), "Bad start line, node line number %i for: %s\n" % (
Expand Down

0 comments on commit ee0c653

Please sign in to comment.