| 1 |
import enum |
| 2 |
from io import StringIO |
| 3 |
|
| 4 |
__all__ = ['Class'] |
| 5 |
|
| 6 |
#: documentation for the integer |
| 7 |
integer = 1 |
| 8 |
|
| 9 |
|
| 10 |
def raises(exc, func, *args, **kwds): |
| 11 |
"""Raise AssertionError if ``func(*args, **kwds)`` does not raise *exc*.""" |
| 12 |
pass |
| 13 |
|
| 14 |
|
| 15 |
class CustomEx(Exception): |
| 16 |
"""My custom exception.""" |
| 17 |
|
| 18 |
def f(self): |
| 19 |
"""Exception method.""" |
| 20 |
|
| 21 |
|
| 22 |
class CustomDataDescriptor: |
| 23 |
"""Descriptor class docstring.""" |
| 24 |
|
| 25 |
def __init__(self, doc): |
| 26 |
self.__doc__ = doc |
| 27 |
|
| 28 |
def __get__(self, obj, type=None): |
| 29 |
if obj is None: |
| 30 |
return self |
| 31 |
return 42 |
| 32 |
|
| 33 |
def meth(self): |
| 34 |
"""Function.""" |
| 35 |
return 'The Answer' |
| 36 |
|
| 37 |
|
| 38 |
class CustomDataDescriptorMeta(type): |
| 39 |
"""Descriptor metaclass docstring.""" |
| 40 |
|
| 41 |
|
| 42 |
class CustomDataDescriptor2(CustomDataDescriptor): |
| 43 |
"""Descriptor class with custom metaclass docstring.""" |
| 44 |
|
| 45 |
__metaclass__ = CustomDataDescriptorMeta |
| 46 |
|
| 47 |
|
| 48 |
def _funky_classmethod(name, b, c, d, docstring=None): |
| 49 |
"""Generates a classmethod for a class from a template by filling out some arguments.""" |
| 50 |
|
| 51 |
def template(cls, a, b, c, d=4, e=5, f=6): |
| 52 |
return a, b, c, d, e, f |
| 53 |
|
| 54 |
from functools import partial |
| 55 |
|
| 56 |
function = partial(template, b=b, c=c, d=d) |
| 57 |
function.__name__ = name |
| 58 |
function.__doc__ = docstring |
| 59 |
return classmethod(function) |
| 60 |
|
| 61 |
|
| 62 |
class Base: |
| 63 |
def inheritedmeth(self): |
| 64 |
"""Inherited function.""" |
| 65 |
|
| 66 |
|
| 67 |
class Derived(Base): |
| 68 |
def inheritedmeth(self): |
| 69 |
# no docstring here |
| 70 |
pass |
| 71 |
|
| 72 |
|
| 73 |
class Class(Base): |
| 74 |
"""Class to document.""" |
| 75 |
|
| 76 |
descr = CustomDataDescriptor('Descriptor instance docstring.') |
| 77 |
|
| 78 |
def meth(self): |
| 79 |
"""Function.""" |
| 80 |
|
| 81 |
def undocmeth(self): |
| 82 |
pass |
| 83 |
|
| 84 |
def skipmeth(self): |
| 85 |
"""Method that should be skipped.""" |
| 86 |
|
| 87 |
def excludemeth(self): |
| 88 |
"""Method that should be excluded.""" |
| 89 |
|
| 90 |
# should not be documented |
| 91 |
skipattr = 'foo' |
| 92 |
|
| 93 |
#: should be documented -- süß |
| 94 |
attr = 'bar' |
| 95 |
|
| 96 |
@property |
| 97 |
def prop(self): |
| 98 |
"""Property.""" |
| 99 |
|
| 100 |
docattr = 'baz' |
| 101 |
"""should likewise be documented -- süß""" |
| 102 |
|
| 103 |
udocattr = 'quux' |
| 104 |
"""should be documented as well - süß""" |
| 105 |
|
| 106 |
# initialized to any class imported from another module |
| 107 |
mdocattr = StringIO() |
| 108 |
"""should be documented as well - süß""" |
| 109 |
|
| 110 |
roger = _funky_classmethod('roger', 2, 3, 4) |
| 111 |
|
| 112 |
moore = _funky_classmethod( |
| 113 |
'moore', 9, 8, 7, docstring='moore(a, e, f) -> happiness' |
| 114 |
) |
| 115 |
|
| 116 |
def __init__(self, arg): |
| 117 |
self.inst_attr_inline = None #: an inline documented instance attr |
| 118 |
#: a documented instance attribute |
| 119 |
self.inst_attr_comment = None |
| 120 |
self.inst_attr_string = None |
| 121 |
"""a documented instance attribute""" |
| 122 |
self._private_inst_attr = None #: a private instance attribute |
| 123 |
|
| 124 |
def __special1__(self): # NoQA: PLW3201 |
| 125 |
"""documented special method""" |
| 126 |
|
| 127 |
def __special2__(self): # NoQA: PLW3201 |
| 128 |
# undocumented special method |
| 129 |
pass |
| 130 |
|
| 131 |
|
| 132 |
class CustomDict(dict): # NoQA: FURB189 |
| 133 |
"""Docstring.""" |
| 134 |
|
| 135 |
|
| 136 |
def function(foo, *args, **kwds): |
| 137 |
"""Return spam.""" |
| 138 |
pass |
| 139 |
|
| 140 |
|
| 141 |
class Outer: |
| 142 |
"""Foo""" |
| 143 |
|
| 144 |
class Inner: |
| 145 |
"""Foo""" |
| 146 |
|
| 147 |
def meth(self): |
| 148 |
"""Foo""" |
| 149 |
|
| 150 |
# should be documented as an alias |
| 151 |
factory = dict |
| 152 |
|
| 153 |
|
| 154 |
class DocstringSig: |
| 155 |
def meth(self): |
| 156 |
"""meth(FOO, BAR=1) -> BAZ |
| 157 |
First line of docstring |
| 158 |
|
| 159 |
rest of docstring |
| 160 |
""" |
| 161 |
|
| 162 |
def meth2(self): |
| 163 |
"""First line, no signature |
| 164 |
Second line followed by indentation:: |
| 165 |
|
| 166 |
indented line |
| 167 |
""" |
| 168 |
|
| 169 |
@property |
| 170 |
def prop1(self): |
| 171 |
"""DocstringSig.prop1(self) |
| 172 |
First line of docstring |
| 173 |
""" |
| 174 |
return 123 |
| 175 |
|
| 176 |
@property |
| 177 |
def prop2(self): |
| 178 |
"""First line of docstring |
| 179 |
Second line of docstring |
| 180 |
""" |
| 181 |
return 456 |
| 182 |
|
| 183 |
|
| 184 |
class StrRepr(str): # NoQA: FURB189,SLOT000 |
| 185 |
def __repr__(self): |
| 186 |
return self |
| 187 |
|
| 188 |
|
| 189 |
class AttCls: |
| 190 |
a1 = StrRepr('hello\nworld') |
| 191 |
a2 = None |
| 192 |
|
| 193 |
|
| 194 |
class InstAttCls: |
| 195 |
"""Class with documented class and instance attributes.""" |
| 196 |
|
| 197 |
#: Doc comment for class attribute InstAttCls.ca1. |
| 198 |
#: It can have multiple lines. |
| 199 |
ca1 = 'a' |
| 200 |
|
| 201 |
ca2 = 'b' #: Doc comment for InstAttCls.ca2. One line only. |
| 202 |
|
| 203 |
ca3 = 'c' |
| 204 |
"""Docstring for class attribute InstAttCls.ca3.""" |
| 205 |
|
| 206 |
def __init__(self): |
| 207 |
#: Doc comment for instance attribute InstAttCls.ia1 |
| 208 |
self.ia1 = 'd' |
| 209 |
|
| 210 |
self.ia2 = 'e' |
| 211 |
"""Docstring for instance attribute InstAttCls.ia2.""" |
| 212 |
|
| 213 |
|
| 214 |
class EnumCls(enum.Enum): |
| 215 |
"""this is enum class""" |
| 216 |
|
| 217 |
#: doc for val1 |
| 218 |
val1 = 12 |
| 219 |
val2 = 23 #: doc for val2 |
| 220 |
val3 = 34 |
| 221 |
"""doc for val3""" |