@@ -1762,13 +1762,27 @@ def check_numpy_content(self, definition, docstring):
1762
1762
"""Check the content of the docstring for numpy conventions."""
1763
1763
pass
1764
1764
1765
- @ check_for ( Definition )
1766
- def check_numpy ( self , definition , docstring ):
1767
- """D403: First word of the first line should be properly capitalized.
1765
+ def check_numpy_parameters ( self , section , content , definition , docstring ):
1766
+ print "LALALAL"
1767
+ yield
1768
1768
1769
- The [first line of a] docstring is a phrase ending in a period.
1769
+ def _check_numpy_section (self , section , content , definition , docstring ):
1770
+ """Check the content of the docstring for numpy conventions."""
1771
+ method_name = "check_numpy_%s" % section
1772
+ if hasattr (self , method_name ):
1773
+ gen_func = getattr (self , method_name )
1770
1774
1771
- """
1775
+ for err in gen_func (section , content , definition , docstring ):
1776
+ yield err
1777
+ else :
1778
+ print "Now checking numpy section %s" % section
1779
+ for l in content :
1780
+ print "##" , l
1781
+
1782
+
1783
+ @check_for (Definition )
1784
+ def check_numpy (self , definition , docstring ):
1785
+ """Parse the general structure of a numpy docstring and check it."""
1772
1786
if not docstring :
1773
1787
return
1774
1788
@@ -1780,6 +1794,10 @@ def check_numpy(self, definition, docstring):
1780
1794
lines_generator = ScrollableGenerator (lines [1 :]) # Skipping first line
1781
1795
indent = self ._get_docstring_indent (definition , docstring )
1782
1796
1797
+ current_section = None
1798
+ curr_section_lines = []
1799
+ start_collecting_lines = False
1800
+
1783
1801
for line in lines_generator :
1784
1802
for section in self .ALL_NUMPY_SECTIONS :
1785
1803
with_colon = section .lower () + ':'
@@ -1800,17 +1818,53 @@ def check_numpy(self, definition, docstring):
1800
1818
yield D214 (section )
1801
1819
1802
1820
if section not in line :
1821
+ # The capitalized section string is not in the line,
1822
+ # meaning that the word appears there but not
1823
+ # properly capitalized.
1803
1824
yield D405 (section , line .strip ())
1804
1825
elif line .strip ().lower () == with_colon :
1826
+ # The section name should not end with a colon.
1805
1827
yield D406 (section , line .strip ())
1806
1828
1807
1829
if next_line .strip () != "-" * len (section ):
1830
+ # The length of the underlining dashes does not
1831
+ # match the length of the section name.
1808
1832
yield D407 (section , len (section ))
1833
+
1834
+ # At this point, we're done with the structured part of
1835
+ # the section and its underline.
1836
+ # We will not collect the content of each section and
1837
+ # let section handlers deal with it.
1838
+
1839
+ if current_section is not None :
1840
+ for err in self ._check_numpy_section (
1841
+ current_section ,
1842
+ curr_section_lines ,
1843
+ definition ,
1844
+ docstring ):
1845
+ yield err
1846
+
1847
+ start_collecting_lines = True
1848
+ current_section = section .lower ()
1849
+ curr_section_lines = []
1809
1850
else :
1810
1851
# The next line does not contain only dashes, so it's
1811
1852
# not likely to be a section header.
1812
1853
lines_generator .scroll_back ()
1813
1854
1855
+ if current_section is not None :
1856
+ if start_collecting_lines :
1857
+ start_collecting_lines = False
1858
+ else :
1859
+ curr_section_lines .append (line )
1860
+
1861
+ if current_section is not None :
1862
+ for err in self ._check_numpy_section (current_section ,
1863
+ curr_section_lines ,
1864
+ definition ,
1865
+ docstring ):
1866
+ yield err
1867
+
1814
1868
1815
1869
class ScrollableGenerator (object ):
1816
1870
"""A generator over a list that can be moved back during iteration."""
@@ -1860,9 +1914,12 @@ def foo():
1860
1914
Parameters
1861
1915
----------
1862
1916
1863
- This is a string that defines some things, such as the following
1864
- parameters
1865
- a, b, d.
1917
+ This is a string that defines some things.
1918
+
1919
+ Returns
1920
+ -------
1921
+
1922
+ Nothing.
1866
1923
"""
1867
1924
1868
1925
if __name__ == '__main__' :
0 commit comments