objects
This module defines the documented objects classes.
- the generic
Object
class - the
Module
class - the
Class
class - the
Method
class - the
Function
class - the
Attribute
class
Note that properties are considered attributes, because they are used like such.
It also defines a convenient Source
class to represent source code.
Attribute
¤
Bases: Object
A class to store information about an attribute.
It accepts an additional attr_type
argument at instantiation.
Source code in src/pytkdocs/objects.py
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
|
__init__(*args, attr_type=None, **kwargs)
¤
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Any
|
Arguments passed to the parent class Initialize the object. |
()
|
attr_type
|
Optional[Any]
|
The attribute type. |
None
|
**kwargs
|
Any
|
Arguments passed to the parent class Initialize the object. |
{}
|
Source code in src/pytkdocs/objects.py
393 394 395 396 397 398 399 400 401 402 |
|
Class
¤
Bases: Object
A class to store information about a class.
Source code in src/pytkdocs/objects.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
|
__init__(*args, bases=None, **kwargs)
¤
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Any
|
Arguments passed to the parent class Initialize the object. |
()
|
bases
|
Optional[list[str]]
|
The base classes (dotted paths). |
None
|
**kwargs
|
Any
|
Arguments passed to the parent class Initialize the object. |
{}
|
Source code in src/pytkdocs/objects.py
333 334 335 336 337 338 339 340 341 342 |
|
Function
¤
Bases: Object
A class to store information about a function.
It accepts an additional signature
argument at instantiation.
Source code in src/pytkdocs/objects.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
|
__init__(*args, signature=None, **kwargs)
¤
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Any
|
Arguments passed to the parent class Initialize the object. |
()
|
signature
|
Optional[Signature]
|
The function signature. |
None
|
**kwargs
|
Any
|
Arguments passed to the parent class Initialize the object. |
{}
|
Source code in src/pytkdocs/objects.py
353 354 355 356 357 358 359 360 361 362 |
|
Method
¤
Bases: Object
A class to store information about a method.
It accepts an additional signature
argument at instantiation.
Source code in src/pytkdocs/objects.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
|
__init__(*args, signature=None, **kwargs)
¤
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Any
|
Arguments passed to the parent class Initialize the object. |
()
|
signature
|
Optional[Signature]
|
The function signature. |
None
|
**kwargs
|
Any
|
Arguments passed to the parent class Initialize the object. |
{}
|
Source code in src/pytkdocs/objects.py
373 374 375 376 377 378 379 380 381 382 |
|
Module
¤
Bases: Object
A class to store information about a module.
Source code in src/pytkdocs/objects.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
|
file_name
property
¤
Return the base name of the module file, without the extension.
Returns:
Type | Description |
---|---|
str
|
The module file's base name. |
Object
¤
A base class to store information about a Python object.
Each instance additionally stores references to its children, grouped by category.
Source code in src/pytkdocs/objects.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
|
attributes = []
instance-attribute
¤
The list of all the object's attributes.
category
property
¤
Return the object's category.
Returns:
Type | Description |
---|---|
str
|
The object's category (module, class, function, method or attribute). |
children = []
instance-attribute
¤
The list of all the object's children.
classes = []
instance-attribute
¤
The list of all the object's classes.
docstring = docstring
instance-attribute
¤
The object's docstring.
docstring_errors = []
instance-attribute
¤
The errors detected while parsing the docstring.
docstring_sections = []
instance-attribute
¤
The object's docstring parsed into sections.
file_path = file_path
instance-attribute
¤
The file path of the object's direct parent module.
functions = []
instance-attribute
¤
The list of all the object's functions.
methods = []
instance-attribute
¤
The list of all the object's methods.
modules = []
instance-attribute
¤
The list of all the object's submodules.
name = name
instance-attribute
¤
The object's name.
name_properties
property
¤
Return the object's name properties.
Returns:
Type | Description |
---|---|
list[str]
|
The object's name properties (private, class-private, special). |
name_to_check
property
¤
Return the attribute to check against name-properties regular expressions (private, class-private, special).
Returns:
Type | Description |
---|---|
str
|
The attribute to check (its name). |
parent = None
instance-attribute
¤
The object's parent (another instance of a subclass of Object
).
parent_path
property
¤
Return the parent's path, computed from the current path.
The parent object path is not used: this property is used to see if an object is really related to another one, to add it as a child to the other. When we do that, the child doesn't even have a parent.
Returns:
Type | Description |
---|---|
str
|
The dotted path of the parent object. |
path = path
instance-attribute
¤
The object's dotted-path.
possible_name_properties = []
class-attribute
instance-attribute
¤
The properties that we can apply to the object based on its name.
The applicable properties vary from one subclass of Object
to another.
properties = properties or []
instance-attribute
¤
The object's properties.
relative_file_path
property
¤
Return the relative file path of the object.
It is the relative path to the object's module, starting at the path of the top-most package it is contained in.
For example:
- package is
a
- package absolute path is
/abs/path/to/a
- module is
a.b.c
- object is
c
or anything defined inc
- relative file path is
a/b/c.py
If the relative file path cannot be determined, the value returned is ""
(empty string).
Returns:
Type | Description |
---|---|
str
|
The path relative to the object's package. |
root
property
¤
source = source
instance-attribute
¤
The object's source code.
__init__(name, path, file_path, docstring='', properties=None, source=None)
¤
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The object's name. |
required |
path
|
str
|
The object's dotted-path. |
required |
file_path
|
str
|
The file path of the object's direct parent module. |
required |
docstring
|
Optional[str]
|
The object's docstring. |
''
|
properties
|
Optional[list[str]]
|
The object's properties. |
None
|
source
|
Optional[Source]
|
The object's source code. |
None
|
Source code in src/pytkdocs/objects.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
add_child(obj)
¤
Add an object as a child of this object.
If the child computed parent_path
is not equal to this object's path, abort.
Append the child to the children
list, and to the right category list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Object
|
An instance of documented object. |
required |
Source code in src/pytkdocs/objects.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
|
add_children(children)
¤
Add a list of objects as children of this object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
children
|
list[Object]
|
The list of children to add. |
required |
Source code in src/pytkdocs/objects.py
256 257 258 259 260 261 262 263 |
|
has_contents()
cached
¤
Tells if the object has "contents".
An object has contents when:
- it is the root of the object tree
- it has a docstring
- at least one of its children (whatever the depth) has contents
The value is cached, so this method should be called last, when the tree doesn't change anymore.
Returns:
Type | Description |
---|---|
bool
|
Whether this object has contents or not. |
Source code in src/pytkdocs/objects.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
|
parse_all_docstrings(parser)
¤
Recursively parse the docstring of this object and its children.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parser
|
Parser
|
A parser to parse the docstrings. |
required |
Source code in src/pytkdocs/objects.py
278 279 280 281 282 283 284 285 286 |
|
parse_docstring(parser, **context)
¤
Parse the docstring of this object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parser
|
Parser
|
A parser to parse the docstrings. |
required |
**context
|
Any
|
Additional context to use when parsing. |
{}
|
Source code in src/pytkdocs/objects.py
265 266 267 268 269 270 271 272 273 274 275 276 |
|
Source
¤
Helper class to represent source code.
It is simply used to wrap the result of
inspect.getsourceslines
.
Source code in src/pytkdocs/objects.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
code = code
instance-attribute
¤
The code, as a single string.
line_start = line_start
instance-attribute
¤
The first line number.
__init__(lines, line_start)
¤
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lines
|
Union[str, list[str]]
|
A list of strings. The strings should have trailing newlines. |
required |
line_start
|
int
|
The line number of where the code starts in the file. |
required |
Source code in src/pytkdocs/objects.py
35 36 37 38 39 40 41 42 43 44 45 46 |
|