mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #1789 :pyobject:
option of literalinclude
directive includes following lines after definitions
This commit is contained in:
parent
629961ebfe
commit
aa66e7860b
2
CHANGES
2
CHANGES
@ -5,6 +5,8 @@ Bugs fixed
|
||||
----------
|
||||
|
||||
* #1788: graphviz extension raises exception when caption option is present.
|
||||
* #1789: ``:pyobject:`` option of ``literalinclude`` directive includes following
|
||||
lines after class definitions
|
||||
|
||||
|
||||
Release 1.3.1 (released Mar 17, 2015)
|
||||
|
@ -10,6 +10,7 @@
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
import re
|
||||
import sys
|
||||
from os import path
|
||||
|
||||
@ -45,6 +46,8 @@ number2name.update(token.tok_name)
|
||||
|
||||
_eq = nodes.Leaf(token.EQUAL, '=')
|
||||
|
||||
emptyline_re = re.compile('^\s*(#.*)?$')
|
||||
|
||||
|
||||
class AttrDocVisitor(nodes.NodeVisitor):
|
||||
"""
|
||||
@ -289,8 +292,9 @@ class ModuleAnalyzer(object):
|
||||
indent = 0
|
||||
defline = False
|
||||
expect_indent = False
|
||||
emptylines = 0
|
||||
|
||||
def tokeniter(ignore = (token.COMMENT, token.NL)):
|
||||
def tokeniter(ignore = (token.COMMENT,)):
|
||||
for tokentup in self.tokens:
|
||||
if tokentup[0] not in ignore:
|
||||
yield tokentup
|
||||
@ -303,7 +307,7 @@ class ModuleAnalyzer(object):
|
||||
dtype, fullname, startline, _ = stack.pop()
|
||||
endline = epos[0]
|
||||
namespace.pop()
|
||||
result[fullname] = (dtype, startline, endline)
|
||||
result[fullname] = (dtype, startline, endline - emptylines)
|
||||
expect_indent = False
|
||||
if tok in ('def', 'class'):
|
||||
name = next(tokeniter)[1]
|
||||
@ -322,7 +326,7 @@ class ModuleAnalyzer(object):
|
||||
dtype, fullname, startline, _ = stack.pop()
|
||||
endline = spos[0]
|
||||
namespace.pop()
|
||||
result[fullname] = (dtype, startline, endline)
|
||||
result[fullname] = (dtype, startline, endline - emptylines)
|
||||
elif type == token.NEWLINE:
|
||||
# if this line contained a definition, expect an INDENT
|
||||
# to start the suite; if there is no such INDENT
|
||||
@ -330,6 +334,13 @@ class ModuleAnalyzer(object):
|
||||
if defline:
|
||||
defline = False
|
||||
expect_indent = True
|
||||
emptylines = 0
|
||||
elif type == token.NL:
|
||||
# count up if line is empty or comment only
|
||||
if emptyline_re.match(line):
|
||||
emptylines += 1
|
||||
else:
|
||||
emptylines = 0
|
||||
self.tags = result
|
||||
return result
|
||||
|
||||
|
@ -10,4 +10,5 @@ class Bar:
|
||||
def baz():
|
||||
pass
|
||||
|
||||
# comment after Bar class definition
|
||||
def bar(): pass
|
||||
|
@ -116,7 +116,8 @@ def test_literal_include_linenos(app, status, warning):
|
||||
'10\n'
|
||||
'11\n'
|
||||
'12\n'
|
||||
'13</pre></div></td>')
|
||||
'13\n'
|
||||
'14</pre></div></td>')
|
||||
assert linenos in html
|
||||
|
||||
|
||||
@ -138,7 +139,8 @@ def test_literal_include_lineno_start(app, status, warning):
|
||||
'209\n'
|
||||
'210\n'
|
||||
'211\n'
|
||||
'212</pre></div></td>')
|
||||
'212\n'
|
||||
'213</pre></div></td>')
|
||||
assert linenos in html
|
||||
|
||||
|
||||
@ -168,7 +170,8 @@ def test_literal_include_lineno_match(app, status, warning):
|
||||
'10\n'
|
||||
'11\n'
|
||||
'12\n'
|
||||
'13</pre></div></td>')
|
||||
'13\n'
|
||||
'14</pre></div></td>')
|
||||
assert start_after in html
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user