@@ -1555,15 +1555,41 @@ def entry(
1555
1555
qualname = f'{ self .name } .{ entry_name } '
1556
1556
return self ._node (role , qualname , doc , args = args , indent = indent , ** rst_options )
1557
1557
1558
- def brief (self , doc : str , * , indent : int = 0 , ** options : Any ) -> list [str ]:
1559
- """Generate the brief part of the class being documented."""
1558
+ def preamble_lookup (
1559
+ self , doc : str , * , indent : int = 0 , ** options : Any
1560
+ ) -> list [str ]:
1561
+ assert (
1562
+ doc
1563
+ ), f'enumeration class { self .target !r} should have an explicit docstring'
1564
+
1565
+ args = self ._preamble_args ()
1566
+ return self ._preamble (doc = doc , args = args , indent = indent , ** options )
1567
+
1568
+ def preamble_constructor (
1569
+ self , doc : str , * , indent : int = 0 , ** options : Any
1570
+ ) -> list [str ]:
1560
1571
assert (
1561
1572
doc
1562
1573
), f'enumeration class { self .target !r} should have an explicit docstring'
1563
1574
1564
- args = '(value)'
1575
+ args = self ._preamble_args ()
1576
+ return self ._preamble (doc = doc , args = args , indent = indent , ** options )
1577
+
1578
+ def _preamble (
1579
+ self , * , doc : str , args : str , indent : int = 0 , ** options : Any
1580
+ ) -> list [str ]:
1581
+ """Generate the preamble of the class being documented."""
1565
1582
return self ._node ('class' , self .name , doc , args = args , indent = indent , ** options )
1566
1583
1584
+ @staticmethod
1585
+ def _preamble_args ():
1586
+ """EnumType.__call__() is a dual-purpose method:
1587
+
1588
+ * Look an enum member (valid only if the enum has members)
1589
+ * Create a new enum class (functional API)
1590
+ """
1591
+ return '(value)'
1592
+
1567
1593
def method (
1568
1594
self ,
1569
1595
name : str ,
@@ -1595,7 +1621,7 @@ def test_enum_class(app, autodoc_enum_options):
1595
1621
1596
1622
actual = do_autodoc (app , 'class' , fmt .target , options )
1597
1623
assert list (actual ) == [
1598
- * fmt .brief ('this is enum class' ),
1624
+ * fmt .preamble_lookup ('this is enum class' ),
1599
1625
* fmt .method (
1600
1626
'say_goodbye' , 'a classmethod says good-bye to you.' , 'classmethod'
1601
1627
),
@@ -1611,7 +1637,7 @@ def test_enum_class(app, autodoc_enum_options):
1611
1637
# redefined by the user in one of the bases.
1612
1638
actual = do_autodoc (app , 'class' , fmt .target , options | {'inherited-members' : None })
1613
1639
assert list (actual ) == [
1614
- * fmt .brief ('this is enum class' ),
1640
+ * fmt .preamble_lookup ('this is enum class' ),
1615
1641
* fmt .method (
1616
1642
'say_goodbye' , 'a classmethod says good-bye to you.' , 'classmethod'
1617
1643
),
@@ -1633,7 +1659,7 @@ def test_enum_class_with_data_type(app, autodoc_enum_options):
1633
1659
1634
1660
actual = do_autodoc (app , 'class' , fmt .target , autodoc_enum_options )
1635
1661
assert list (actual ) == [
1636
- * fmt .brief ('this is enum class' ),
1662
+ * fmt .preamble_lookup ('this is enum class' ),
1637
1663
* fmt .method ('say_goodbye' , 'docstring' , 'classmethod' ),
1638
1664
* fmt .method ('say_hello' , 'docstring' ),
1639
1665
* fmt .member ('x' , 'x' , '' ),
@@ -1642,7 +1668,7 @@ def test_enum_class_with_data_type(app, autodoc_enum_options):
1642
1668
options = autodoc_enum_options | {'inherited-members' : None }
1643
1669
actual = do_autodoc (app , 'class' , fmt .target , options )
1644
1670
assert list (actual ) == [
1645
- * fmt .brief ('this is enum class' ),
1671
+ * fmt .preamble_lookup ('this is enum class' ),
1646
1672
* fmt .entry ('dtype' , 'docstring' , role = 'property' ),
1647
1673
* fmt .method ('isupper' , 'inherited' ),
1648
1674
* fmt .method ('say_goodbye' , 'docstring' , 'classmethod' ),
@@ -1657,7 +1683,7 @@ def test_enum_class_with_mixin_type(app, autodoc_enum_options):
1657
1683
1658
1684
actual = do_autodoc (app , 'class' , fmt .target , autodoc_enum_options )
1659
1685
assert list (actual ) == [
1660
- * fmt .brief ('this is enum class' ),
1686
+ * fmt .preamble_lookup ('this is enum class' ),
1661
1687
* fmt .method ('say_goodbye' , 'docstring' , 'classmethod' ),
1662
1688
* fmt .method ('say_hello' , 'docstring' ),
1663
1689
* fmt .member ('x' , 'X' , '' ),
@@ -1666,7 +1692,7 @@ def test_enum_class_with_mixin_type(app, autodoc_enum_options):
1666
1692
options = autodoc_enum_options | {'inherited-members' : None }
1667
1693
actual = do_autodoc (app , 'class' , fmt .target , options )
1668
1694
assert list (actual ) == [
1669
- * fmt .brief ('this is enum class' ),
1695
+ * fmt .preamble_lookup ('this is enum class' ),
1670
1696
* fmt .method ('say_goodbye' , 'docstring' , 'classmethod' ),
1671
1697
* fmt .method ('say_hello' , 'docstring' ),
1672
1698
* fmt .entry ('value' , 'uppercased' , role = 'property' ),
@@ -1680,14 +1706,14 @@ def test_enum_class_with_mixin_type_and_inheritence(app, autodoc_enum_options):
1680
1706
1681
1707
actual = do_autodoc (app , 'class' , fmt .target , autodoc_enum_options )
1682
1708
assert list (actual ) == [
1683
- * fmt .brief ('this is enum class' ),
1709
+ * fmt .preamble_lookup ('this is enum class' ),
1684
1710
* fmt .member ('x' , 'X' , '' ),
1685
1711
]
1686
1712
1687
1713
options = autodoc_enum_options | {'inherited-members' : None }
1688
1714
actual = do_autodoc (app , 'class' , fmt .target , options )
1689
1715
assert list (actual ) == [
1690
- * fmt .brief ('this is enum class' ),
1716
+ * fmt .preamble_lookup ('this is enum class' ),
1691
1717
* fmt .method ('say_goodbye' , 'inherited' , 'classmethod' ),
1692
1718
* fmt .method ('say_hello' , 'inherited' ),
1693
1719
* fmt .entry ('value' , 'uppercased' , role = 'property' ),
@@ -1701,7 +1727,7 @@ def test_enum_class_with_mixin_enum_type(app, autodoc_enum_options):
1701
1727
1702
1728
actual = do_autodoc (app , 'class' , fmt .target , autodoc_enum_options )
1703
1729
assert list (actual ) == [
1704
- * fmt .brief ('this is enum class' ),
1730
+ * fmt .preamble_lookup ('this is enum class' ),
1705
1731
# override() is overridden at the class level so it should be rendered
1706
1732
* fmt .method ('override' , 'overridden' ),
1707
1733
# say_goodbye() and say_hello() are not rendered since they are inherited
@@ -1711,7 +1737,7 @@ def test_enum_class_with_mixin_enum_type(app, autodoc_enum_options):
1711
1737
options = autodoc_enum_options | {'inherited-members' : None }
1712
1738
actual = do_autodoc (app , 'class' , fmt .target , options )
1713
1739
assert list (actual ) == [
1714
- * fmt .brief ('this is enum class' ),
1740
+ * fmt .preamble_lookup ('this is enum class' ),
1715
1741
* fmt .method ('override' , 'overridden' ),
1716
1742
* fmt .method ('say_goodbye' , 'inherited' , 'classmethod' ),
1717
1743
* fmt .method ('say_hello' , 'inherited' ),
@@ -1725,7 +1751,7 @@ def test_enum_class_with_mixin_and_data_type(app, autodoc_enum_options):
1725
1751
1726
1752
actual = do_autodoc (app , 'class' , fmt .target , autodoc_enum_options )
1727
1753
assert list (actual ) == [
1728
- * fmt .brief ('this is enum class' ),
1754
+ * fmt .preamble_lookup ('this is enum class' ),
1729
1755
* fmt .method ('isupper' , 'overridden' ),
1730
1756
* fmt .method ('say_goodbye' , 'overridden' , 'classmethod' ),
1731
1757
* fmt .method ('say_hello' , 'overridden' ),
@@ -1736,7 +1762,7 @@ def test_enum_class_with_mixin_and_data_type(app, autodoc_enum_options):
1736
1762
options = autodoc_enum_options | {'special-members' : '__str__' }
1737
1763
actual = do_autodoc (app , 'class' , fmt .target , options )
1738
1764
assert list (actual ) == [
1739
- * fmt .brief ('this is enum class' ),
1765
+ * fmt .preamble_lookup ('this is enum class' ),
1740
1766
* fmt .method ('__str__' , 'overridden' ),
1741
1767
* fmt .method ('isupper' , 'overridden' ),
1742
1768
* fmt .method ('say_goodbye' , 'overridden' , 'classmethod' ),
@@ -1747,7 +1773,7 @@ def test_enum_class_with_mixin_and_data_type(app, autodoc_enum_options):
1747
1773
options = autodoc_enum_options | {'inherited-members' : None }
1748
1774
actual = do_autodoc (app , 'class' , fmt .target , options )
1749
1775
assert list (actual ) == [
1750
- * fmt .brief ('this is enum class' ),
1776
+ * fmt .preamble_lookup ('this is enum class' ),
1751
1777
* fmt .entry ('dtype' , 'docstring' , role = 'property' ),
1752
1778
* fmt .method ('isupper' , 'overridden' ),
1753
1779
* fmt .method ('say_goodbye' , 'overridden' , 'classmethod' ),
@@ -1763,7 +1789,7 @@ def test_enum_with_parent_enum(app, autodoc_enum_options):
1763
1789
1764
1790
actual = do_autodoc (app , 'class' , fmt .target , autodoc_enum_options )
1765
1791
assert list (actual ) == [
1766
- * fmt .brief ('this is enum class' ),
1792
+ * fmt .preamble_lookup ('this is enum class' ),
1767
1793
* fmt .method ('isupper' , 'overridden' ),
1768
1794
* fmt .member ('x' , 'X' , '' ),
1769
1795
]
@@ -1772,7 +1798,7 @@ def test_enum_with_parent_enum(app, autodoc_enum_options):
1772
1798
options = autodoc_enum_options | {'special-members' : '__str__' }
1773
1799
actual = do_autodoc (app , 'class' , fmt .target , options )
1774
1800
assert list (actual ) == [
1775
- * fmt .brief ('this is enum class' ),
1801
+ * fmt .preamble_lookup ('this is enum class' ),
1776
1802
* fmt .method ('__str__' , 'overridden' ),
1777
1803
* fmt .method ('isupper' , 'overridden' ),
1778
1804
* fmt .member ('x' , 'X' , '' ),
@@ -1781,7 +1807,7 @@ def test_enum_with_parent_enum(app, autodoc_enum_options):
1781
1807
options = autodoc_enum_options | {'inherited-members' : None }
1782
1808
actual = do_autodoc (app , 'class' , fmt .target , options )
1783
1809
assert list (actual ) == [
1784
- * fmt .brief ('this is enum class' ),
1810
+ * fmt .preamble_lookup ('this is enum class' ),
1785
1811
* fmt .entry ('dtype' , 'docstring' , role = 'property' ),
1786
1812
* fmt .method ('isupper' , 'overridden' ),
1787
1813
* fmt .method ('override' , 'inherited' ),
@@ -1798,28 +1824,28 @@ def test_enum_sunder_method(app, autodoc_enum_options):
1798
1824
1799
1825
fmt = _EnumFormatter ('EnumSunderMissingInNonEnumMixin' )
1800
1826
actual = do_autodoc (app , 'class' , fmt .target , autodoc_enum_options )
1801
- assert list (actual ) == [* fmt .brief ('this is enum class' )]
1827
+ assert list (actual ) == [* fmt .preamble_constructor ('this is enum class' )]
1802
1828
actual = do_autodoc (app , 'class' , fmt .target , autodoc_enum_options | PRIVATE )
1803
- assert list (actual ) == [* fmt .brief ('this is enum class' )]
1829
+ assert list (actual ) == [* fmt .preamble_constructor ('this is enum class' )]
1804
1830
1805
1831
fmt = _EnumFormatter ('EnumSunderMissingInEnumMixin' )
1806
1832
actual = do_autodoc (app , 'class' , fmt .target , autodoc_enum_options )
1807
- assert list (actual ) == [* fmt .brief ('this is enum class' )]
1833
+ assert list (actual ) == [* fmt .preamble_constructor ('this is enum class' )]
1808
1834
actual = do_autodoc (app , 'class' , fmt .target , autodoc_enum_options | PRIVATE )
1809
- assert list (actual ) == [* fmt .brief ('this is enum class' )]
1835
+ assert list (actual ) == [* fmt .preamble_constructor ('this is enum class' )]
1810
1836
1811
1837
fmt = _EnumFormatter ('EnumSunderMissingInDataType' )
1812
1838
actual = do_autodoc (app , 'class' , fmt .target , autodoc_enum_options )
1813
- assert list (actual ) == [* fmt .brief ('this is enum class' )]
1839
+ assert list (actual ) == [* fmt .preamble_constructor ('this is enum class' )]
1814
1840
actual = do_autodoc (app , 'class' , fmt .target , autodoc_enum_options | PRIVATE )
1815
- assert list (actual ) == [* fmt .brief ('this is enum class' )]
1841
+ assert list (actual ) == [* fmt .preamble_constructor ('this is enum class' )]
1816
1842
1817
1843
fmt = _EnumFormatter ('EnumSunderMissingInClass' )
1818
1844
actual = do_autodoc (app , 'class' , fmt .target , autodoc_enum_options )
1819
- assert list (actual ) == [* fmt .brief ('this is enum class' )]
1845
+ assert list (actual ) == [* fmt .preamble_constructor ('this is enum class' )]
1820
1846
actual = do_autodoc (app , 'class' , fmt .target , autodoc_enum_options | PRIVATE )
1821
1847
assert list (actual ) == [
1822
- * fmt .brief ('this is enum class' ),
1848
+ * fmt .preamble_constructor ('this is enum class' ),
1823
1849
* fmt .method ('_missing_' , 'docstring' , 'classmethod' , args = '(value)' ),
1824
1850
]
1825
1851
@@ -1834,21 +1860,21 @@ def test_enum_inherited_sunder_method(app, autodoc_enum_options):
1834
1860
fmt = _EnumFormatter ('EnumSunderMissingInNonEnumMixin' )
1835
1861
actual = do_autodoc (app , 'class' , fmt .target , options )
1836
1862
assert list (actual ) == [
1837
- * fmt .brief ('this is enum class' ),
1863
+ * fmt .preamble_constructor ('this is enum class' ),
1838
1864
* fmt .method ('_missing_' , 'inherited' , 'classmethod' , args = '(value)' ),
1839
1865
]
1840
1866
1841
1867
fmt = _EnumFormatter ('EnumSunderMissingInEnumMixin' )
1842
1868
actual = do_autodoc (app , 'class' , fmt .target , options )
1843
1869
assert list (actual ) == [
1844
- * fmt .brief ('this is enum class' ),
1870
+ * fmt .preamble_constructor ('this is enum class' ),
1845
1871
* fmt .method ('_missing_' , 'inherited' , 'classmethod' , args = '(value)' ),
1846
1872
]
1847
1873
1848
1874
fmt = _EnumFormatter ('EnumSunderMissingInDataType' )
1849
1875
actual = do_autodoc (app , 'class' , fmt .target , options )
1850
1876
assert list (actual ) == [
1851
- * fmt .brief ('this is enum class' ),
1877
+ * fmt .preamble_constructor ('this is enum class' ),
1852
1878
* fmt .method ('_missing_' , 'inherited' , 'classmethod' , args = '(value)' ),
1853
1879
* fmt .entry ('dtype' , 'docstring' , role = 'property' ),
1854
1880
* fmt .method ('isupper' , 'inherited' ),
@@ -1857,7 +1883,7 @@ def test_enum_inherited_sunder_method(app, autodoc_enum_options):
1857
1883
fmt = _EnumFormatter ('EnumSunderMissingInClass' )
1858
1884
actual = do_autodoc (app , 'class' , fmt .target , options )
1859
1885
assert list (actual ) == [
1860
- * fmt .brief ('this is enum class' ),
1886
+ * fmt .preamble_constructor ('this is enum class' ),
1861
1887
* fmt .method ('_missing_' , 'docstring' , 'classmethod' , args = '(value)' ),
1862
1888
]
1863
1889
@@ -1866,20 +1892,20 @@ def test_enum_inherited_sunder_method(app, autodoc_enum_options):
1866
1892
def test_enum_custom_name_property (app , autodoc_enum_options ):
1867
1893
fmt = _EnumFormatter ('EnumNamePropertyInNonEnumMixin' )
1868
1894
actual = do_autodoc (app , 'class' , fmt .target , autodoc_enum_options )
1869
- assert list (actual ) == [* fmt .brief ('this is enum class' )]
1895
+ assert list (actual ) == [* fmt .preamble_constructor ('this is enum class' )]
1870
1896
1871
1897
fmt = _EnumFormatter ('EnumNamePropertyInEnumMixin' )
1872
1898
actual = do_autodoc (app , 'class' , fmt .target , autodoc_enum_options )
1873
- assert list (actual ) == [* fmt .brief ('this is enum class' )]
1899
+ assert list (actual ) == [* fmt .preamble_constructor ('this is enum class' )]
1874
1900
1875
1901
fmt = _EnumFormatter ('EnumNamePropertyInDataType' )
1876
1902
actual = do_autodoc (app , 'class' , fmt .target , autodoc_enum_options )
1877
- assert list (actual ) == [* fmt .brief ('this is enum class' )]
1903
+ assert list (actual ) == [* fmt .preamble_constructor ('this is enum class' )]
1878
1904
1879
1905
fmt = _EnumFormatter ('EnumNamePropertyInClass' )
1880
1906
actual = do_autodoc (app , 'class' , fmt .target , autodoc_enum_options )
1881
1907
assert list (actual ) == [
1882
- * fmt .brief ('this is enum class' ),
1908
+ * fmt .preamble_constructor ('this is enum class' ),
1883
1909
* fmt .entry ('name' , 'docstring' , role = 'property' ),
1884
1910
]
1885
1911
@@ -1891,21 +1917,21 @@ def test_enum_inherited_custom_name_property(app, autodoc_enum_options):
1891
1917
fmt = _EnumFormatter ('EnumNamePropertyInNonEnumMixin' )
1892
1918
actual = do_autodoc (app , 'class' , fmt .target , options )
1893
1919
assert list (actual ) == [
1894
- * fmt .brief ('this is enum class' ),
1920
+ * fmt .preamble_constructor ('this is enum class' ),
1895
1921
* fmt .entry ('name' , 'inherited' , role = 'property' ),
1896
1922
]
1897
1923
1898
1924
fmt = _EnumFormatter ('EnumNamePropertyInEnumMixin' )
1899
1925
actual = do_autodoc (app , 'class' , fmt .target , options )
1900
1926
assert list (actual ) == [
1901
- * fmt .brief ('this is enum class' ),
1927
+ * fmt .preamble_constructor ('this is enum class' ),
1902
1928
* fmt .entry ('name' , 'inherited' , role = 'property' ),
1903
1929
]
1904
1930
1905
1931
fmt = _EnumFormatter ('EnumNamePropertyInDataType' )
1906
1932
actual = do_autodoc (app , 'class' , fmt .target , options )
1907
1933
assert list (actual ) == [
1908
- * fmt .brief ('this is enum class' ),
1934
+ * fmt .preamble_constructor ('this is enum class' ),
1909
1935
* fmt .entry ('dtype' , 'docstring' , role = 'property' ),
1910
1936
* fmt .method ('isupper' , 'inherited' ),
1911
1937
* fmt .entry ('name' , 'inherited' , role = 'property' ),
@@ -1914,7 +1940,7 @@ def test_enum_inherited_custom_name_property(app, autodoc_enum_options):
1914
1940
fmt = _EnumFormatter ('EnumNamePropertyInClass' )
1915
1941
actual = do_autodoc (app , 'class' , fmt .target , options )
1916
1942
assert list (actual ) == [
1917
- * fmt .brief ('this is enum class' ),
1943
+ * fmt .preamble_constructor ('this is enum class' ),
1918
1944
* fmt .entry ('name' , 'docstring' , role = 'property' ),
1919
1945
]
1920
1946
0 commit comments