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