Extensions¤
Main API¤
load_extensions ¤
load_extensions(*exts: LoadableExtensionType) -> Extensions
Load configured extensions.
Parameters:
-
(exts¤LoadableExtensionType, default:()) –Extensions with potential configuration options.
Returns:
-
Extensions–An extensions container.
- Changelog 0.46.0 - 2024-06-16
- Guide User guide Manipulating APIs Extending APIs Using extensions
- Reference
griffe Extensions
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 | |
Extension ¤
Base class for Griffe extensions.
Methods:
-
generic_inspect–Extend the base generic inspection with extensions.
-
generic_visit–Visit children nodes.
-
inspect–Inspect a node.
-
on_alias–Run on aliases once the object tree has been fully constructed.
-
on_alias_instance–Run when an Alias has been created.
-
on_attribute–Run on attributes once the object tree has been fully constructed.
-
on_attribute_instance–Run when an Attribute has been created.
-
on_attribute_node–Run when visiting a new attribute node during static/dynamic analysis.
-
on_class–Run on classes once the object tree has been fully constructed.
-
on_class_instance–Run when a Class has been created.
-
on_class_members–Run when members of a Class have been loaded.
-
on_class_node–Run when visiting a new class node during static/dynamic analysis.
-
on_function–Run on functions once the object tree has been fully constructed.
-
on_function_instance–Run when a Function has been created.
-
on_function_node–Run when visiting a new function node during static/dynamic analysis.
-
on_instance–Run when an Object has been created.
-
on_members–Run when members of an Object have been loaded.
-
on_module–Run on modules once the object tree has been fully constructed.
-
on_module_instance–Run when a Module has been created.
-
on_module_members–Run when members of a Module have been loaded.
-
on_module_node–Run when visiting a new module node during static/dynamic analysis.
-
on_node–Run when visiting a new node during static/dynamic analysis.
-
on_object–Run on objects (every kind) once the object tree has been fully constructed.
-
on_package–Run when a package has been completely loaded.
-
on_type_alias–Run on type aliases once the object tree has been fully constructed.
-
on_type_alias_instance–Run when a TypeAlias has been created.
-
on_type_alias_node–Run when visiting a new type alias node during static/dynamic analysis.
-
visit–Visit a node.
generic_inspect ¤
generic_inspect(node: ObjectNode) -> None
Extend the base generic inspection with extensions.
Parameters:
-
(node¤ObjectNode) –The node to inspect.
- Guide User guide Manipulating APIs Extending APIs Writing extensions Visiting trees
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
56 57 58 59 60 61 62 63 64 | |
generic_visit ¤
Visit children nodes.
Parameters:
- Guide User guide Manipulating APIs Extending APIs Writing extensions Visiting trees
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
39 40 41 42 43 44 45 46 | |
inspect ¤
inspect(node: ObjectNode) -> None
Inspect a node.
Parameters:
-
(node¤ObjectNode) –The node to inspect.
- Guide User guide Manipulating APIs Extending APIs Writing extensions Visiting trees
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
48 49 50 51 52 53 54 | |
on_alias ¤
Run on aliases once the object tree has been fully constructed.
Note
This method runs once the object tree has been fully constructed: data is therefore complete and you can safely hook onto this event.
Parameters:
-
(alias¤Alias) –The alias instance.
-
(loader¤GriffeLoader) –The loader currently in use.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide Manipulating APIs Extending APIs Writing extensions Events and hooks Load events
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
411 412 413 414 415 416 417 418 419 420 421 422 | |
on_alias_instance ¤
on_alias_instance(
*,
node: AST | ObjectNode,
alias: Alias,
agent: Visitor | Inspector,
**kwargs: Any,
) -> None
Run when an Alias has been created.
Warning
This method runs while the object tree is still being constructed: data might be incomplete (class inheritance, alias resolution, etc.). Only hook onto this event if you know what you're doing.
Parameters:
-
(node¤AST | ObjectNode) –The currently visited node.
-
(alias¤Alias) –The alias instance.
-
(agent¤Visitor | Inspector) –The analysis agent currently running.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide Manipulating APIs Extending APIs Writing extensions Events and hooks Analysis events
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
on_attribute ¤
Run on attributes once the object tree has been fully constructed.
Note
This method runs once the object tree has been fully constructed: data is therefore complete and you can safely hook onto this event.
Parameters:
-
(attr¤Attribute) –The attribute instance.
-
(loader¤GriffeLoader) –The loader currently in use.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide Manipulating APIs Extending APIs Writing extensions Events and hooks Load events
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
330 331 332 333 334 335 336 337 338 339 340 341 | |
on_attribute_instance ¤
on_attribute_instance(
*,
node: AST | ObjectNode,
attr: Attribute,
agent: Visitor | Inspector,
**kwargs: Any,
) -> None
Run when an Attribute has been created.
Warning
This method runs while the object tree is still being constructed: data might be incomplete (class inheritance, alias resolution, etc.). Only hook onto this event if you know what you're doing.
Parameters:
-
(node¤AST | ObjectNode) –The currently visited node.
-
(attr¤Attribute) –The attribute instance.
-
(agent¤Visitor | Inspector) –The analysis agent currently running.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide
- Manipulating APIs Extending APIs Writing extensions Events and hooks Analysis events
- How-to Supporting custom decorators
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
on_attribute_node ¤
Run when visiting a new attribute node during static/dynamic analysis.
Parameters:
-
(node¤AST | ObjectNode) –The currently visited node.
-
(agent¤Visitor | Inspector) –The analysis agent currently running.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide Manipulating APIs Extending APIs Writing extensions Events and hooks Analysis events
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
299 300 301 302 303 304 305 306 | |
on_class ¤
Run on classes once the object tree has been fully constructed.
Note
This method runs once the object tree has been fully constructed: data is therefore complete and you can safely hook onto this event.
Parameters:
-
(cls¤Class) –The class instance.
-
(loader¤GriffeLoader) –The loader currently in use.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide Manipulating APIs Extending APIs Writing extensions Events and hooks Load events
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
220 221 222 223 224 225 226 227 228 229 230 231 | |
on_class_instance ¤
on_class_instance(
*,
node: AST | ObjectNode,
cls: Class,
agent: Visitor | Inspector,
**kwargs: Any,
) -> None
Run when a Class has been created.
Warning
This method runs while the object tree is still being constructed: data might be incomplete (class inheritance, alias resolution, etc.). Only hook onto this event if you know what you're doing.
Parameters:
-
(node¤AST | ObjectNode) –The currently visited node.
-
(cls¤Class) –The class instance.
-
(agent¤Visitor | Inspector) –The analysis agent currently running.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide
- Manipulating APIs Extending APIs Writing extensions Events and hooks Analysis events
- How-to Supporting custom decorators
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
on_class_members ¤
on_class_members(
*,
node: AST | ObjectNode,
cls: Class,
agent: Visitor | Inspector,
**kwargs: Any,
) -> None
Run when members of a Class have been loaded.
Warning
This method runs while the object tree is still being constructed: data might be incomplete (class inheritance, alias resolution, etc.). Only hook onto this event if you know what you're doing.
Parameters:
-
(node¤AST | ObjectNode) –The currently visited node.
-
(cls¤Class) –The class instance.
-
(agent¤Visitor | Inspector) –The analysis agent currently running.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide Manipulating APIs Extending APIs Writing extensions Events and hooks Analysis events
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
on_class_node ¤
Run when visiting a new class node during static/dynamic analysis.
Parameters:
-
(node¤AST | ObjectNode) –The currently visited node.
-
(agent¤Visitor | Inspector) –The analysis agent currently running.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide Manipulating APIs Extending APIs Writing extensions Events and hooks Analysis events
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
189 190 191 192 193 194 195 196 | |
on_function ¤
Run on functions once the object tree has been fully constructed.
Note
This method runs once the object tree has been fully constructed: data is therefore complete and you can safely hook onto this event.
Parameters:
-
(func¤Function) –The function instance.
-
(loader¤GriffeLoader) –The loader currently in use.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide Manipulating APIs Extending APIs Writing extensions Events and hooks Load events
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
286 287 288 289 290 291 292 293 294 295 296 297 | |
on_function_instance ¤
on_function_instance(
*,
node: AST | ObjectNode,
func: Function,
agent: Visitor | Inspector,
**kwargs: Any,
) -> None
Run when a Function has been created.
Warning
This method runs while the object tree is still being constructed: data might be incomplete (class inheritance, alias resolution, etc.). Only hook onto this event if you know what you're doing.
Parameters:
-
(node¤AST | ObjectNode) –The currently visited node.
-
(func¤Function) –The function instance.
-
(agent¤Visitor | Inspector) –The analysis agent currently running.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide
- Manipulating APIs Extending APIs Writing extensions Events and hooks Analysis events
- How-to Supporting custom decorators
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
on_function_node ¤
Run when visiting a new function node during static/dynamic analysis.
Parameters:
-
(node¤AST | ObjectNode) –The currently visited node.
-
(agent¤Visitor | Inspector) –The analysis agent currently running.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide Manipulating APIs Extending APIs Writing extensions Events and hooks Analysis events
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
255 256 257 258 259 260 261 262 | |
on_instance ¤
on_instance(
*,
node: AST | ObjectNode,
obj: Object,
agent: Visitor | Inspector,
**kwargs: Any,
) -> None
Run when an Object has been created.
Warning
This method runs while the object tree is still being constructed: data might be incomplete (class inheritance, alias resolution, etc.). Only hook onto this event if you know what you're doing.
Parameters:
-
(node¤AST | ObjectNode) –The currently visited node.
-
(obj¤Object) –The object instance.
-
(agent¤Visitor | Inspector) –The analysis agent currently running.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide
- Manipulating APIs Extending APIs Writing extensions Events and hooks Analysis events
- How-to Supporting custom decorators
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
on_members ¤
on_members(
*,
node: AST | ObjectNode,
obj: Object,
agent: Visitor | Inspector,
**kwargs: Any,
) -> None
Run when members of an Object have been loaded.
Warning
This method runs while the object tree is still being constructed: data might be incomplete (class inheritance, alias resolution, etc.). Only hook onto this event if you know what you're doing.
Parameters:
-
(node¤AST | ObjectNode) –The currently visited node.
-
(obj¤Object) –The object instance.
-
(agent¤Visitor | Inspector) –The analysis agent currently running.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide Manipulating APIs Extending APIs Writing extensions Events and hooks Analysis events
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
on_module ¤
Run on modules once the object tree has been fully constructed.
Note
This method runs once the object tree has been fully constructed: data is therefore complete and you can safely hook onto this event.
Parameters:
-
(mod¤Module) –The module instance.
-
(loader¤GriffeLoader) –The loader currently in use.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide Manipulating APIs Extending APIs Writing extensions Events and hooks Load events
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
154 155 156 157 158 159 160 161 162 163 164 165 | |
on_module_instance ¤
on_module_instance(
*,
node: AST | ObjectNode,
mod: Module,
agent: Visitor | Inspector,
**kwargs: Any,
) -> None
Run when a Module has been created.
Warning
This method runs while the object tree is still being constructed: data might be incomplete (class inheritance, alias resolution, etc.). Only hook onto this event if you know what you're doing.
Parameters:
-
(node¤AST | ObjectNode) –The currently visited node.
-
(mod¤Module) –The module instance.
-
(agent¤Visitor | Inspector) –The analysis agent currently running.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide
- Manipulating APIs Extending APIs Writing extensions Events and hooks Analysis events
- How-to Supporting custom decorators
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
on_module_members ¤
on_module_members(
*,
node: AST | ObjectNode,
mod: Module,
agent: Visitor | Inspector,
**kwargs: Any,
) -> None
Run when members of a Module have been loaded.
Warning
This method runs while the object tree is still being constructed: data might be incomplete (class inheritance, alias resolution, etc.). Only hook onto this event if you know what you're doing.
Parameters:
-
(node¤AST | ObjectNode) –The currently visited node.
-
(mod¤Module) –The module instance.
-
(agent¤Visitor | Inspector) –The analysis agent currently running.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide Manipulating APIs Extending APIs Writing extensions Events and hooks Analysis events
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
on_module_node ¤
Run when visiting a new module node during static/dynamic analysis.
Parameters:
-
(node¤AST | ObjectNode) –The currently visited node.
-
(agent¤Visitor | Inspector) –The analysis agent currently running.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide Manipulating APIs Extending APIs Writing extensions Events and hooks Analysis events
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
123 124 125 126 127 128 129 130 | |
on_node ¤
Run when visiting a new node during static/dynamic analysis.
Parameters:
-
(node¤AST | ObjectNode) –The currently visited node.
- Guide User guide Manipulating APIs Extending APIs Writing extensions Events and hooks Analysis events
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
66 67 68 69 70 71 | |
on_object ¤
Run on objects (every kind) once the object tree has been fully constructed.
Note
This method runs once the object tree has been fully constructed: data is therefore complete and you can safely hook onto this event.
Parameters:
-
(obj¤Object) –The object instance.
-
(loader¤GriffeLoader) –The loader currently in use.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide Manipulating APIs Extending APIs Writing extensions Events and hooks Load events
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
95 96 97 98 99 100 101 102 103 104 105 106 | |
on_package ¤
Run when a package has been completely loaded.
Note
This method runs once the object tree has been fully constructed: data is therefore complete and you can safely hook onto this event.
Parameters:
-
(pkg¤Module) –The package (Module) instance.
-
(loader¤GriffeLoader) –The loader currently in use.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide Manipulating APIs Extending APIs Writing extensions Events and hooks Load events
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
424 425 426 427 428 429 430 431 432 433 434 435 | |
on_type_alias ¤
on_type_alias(
*,
type_alias: TypeAlias,
loader: GriffeLoader,
**kwargs: Any,
) -> None
Run on type aliases once the object tree has been fully constructed.
Note
This method runs once the object tree has been fully constructed: data is therefore complete and you can safely hook onto this event.
Parameters:
-
(type_alias¤TypeAlias) –The type alias instance.
-
(loader¤GriffeLoader) –The loader currently in use.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide Manipulating APIs Extending APIs Writing extensions Events and hooks Load events
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
374 375 376 377 378 379 380 381 382 383 384 385 | |
on_type_alias_instance ¤
on_type_alias_instance(
*,
node: AST | ObjectNode,
type_alias: TypeAlias,
agent: Visitor | Inspector,
**kwargs: Any,
) -> None
Run when a TypeAlias has been created.
Warning
This method runs while the object tree is still being constructed: data might be incomplete (class inheritance, alias resolution, etc.). Only hook onto this event if you know what you're doing.
Parameters:
-
(node¤AST | ObjectNode) –The currently visited node.
-
(type_alias¤TypeAlias) –The type alias instance.
-
(agent¤Visitor | Inspector) –The analysis agent currently running.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide
- Manipulating APIs Extending APIs Writing extensions Events and hooks Analysis events
- How-to Supporting custom decorators
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
on_type_alias_node ¤
Run when visiting a new type alias node during static/dynamic analysis.
Parameters:
-
(node¤AST | ObjectNode) –The currently visited node.
-
(agent¤Visitor | Inspector) –The analysis agent currently running.
-
(**kwargs¤Any, default:{}) –For forward-compatibility.
- Guide User guide Manipulating APIs Extending APIs Writing extensions Events and hooks Analysis events
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
343 344 345 346 347 348 349 350 | |
visit ¤
Visit a node.
Parameters:
- Guide User guide Manipulating APIs Extending APIs Writing extensions Visiting trees
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
31 32 33 34 35 36 37 | |
Advanced API¤
Extensions ¤
Extensions(*extensions: Extension)
This class helps iterating on extensions that should run at different times.
Parameters:
- Guide User guide Manipulating APIs Extending APIs Using extensions Programmatically
Methods:
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
445 446 447 448 449 450 451 452 | |
add ¤
add(*extensions: Extension) -> None
Add extensions to this container.
Parameters:
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
454 455 456 457 458 459 460 461 | |
call ¤
Call the extension hook for the given event.
Parameters:
- Guide User guide Manipulating APIs Extending APIs Writing extensions Triggering other extensions
Source code in packages/griffelib/src/griffe/_internal/extensions/base.py
466 467 468 469 470 471 472 473 474 | |
Types¤
LoadableExtensionType module-attribute ¤
All the types that can be passed to load_extensions.
Builtin extensions¤
builtin_extensions module-attribute ¤
The names of built-in Griffe extensions.
DataclassesExtension ¤
Bases: Extension
flowchart TD
griffe.DataclassesExtension[DataclassesExtension]
griffe._internal.extensions.base.Extension[Extension]
griffe._internal.extensions.base.Extension --> griffe.DataclassesExtension
click griffe.DataclassesExtension href "" "griffe.DataclassesExtension"
click griffe._internal.extensions.base.Extension href "" "griffe._internal.extensions.base.Extension"
Built-in extension adding support for dataclasses.
This extension creates __init__ methods of dataclasses if they don't already exist.
Methods:
-
on_package–Hook for loaded packages.
on_package ¤
Hook for loaded packages.
Parameters:
Source code in packages/griffelib/src/griffe/_internal/extensions/dataclasses.py
227 228 229 230 231 232 233 | |
UnpackTypedDictExtension ¤
Bases: Extension
flowchart TD
griffe.UnpackTypedDictExtension[UnpackTypedDictExtension]
griffe._internal.extensions.base.Extension[Extension]
griffe._internal.extensions.base.Extension --> griffe.UnpackTypedDictExtension
click griffe.UnpackTypedDictExtension href "" "griffe.UnpackTypedDictExtension"
click griffe._internal.extensions.base.Extension href "" "griffe._internal.extensions.base.Extension"
An extension to handle Unpack[TypeDict].
Methods:
-
on_class–Add an
__init__method toTypedDictclasses if missing. -
on_function–Expand
**kwargs: Unpack[TypedDict]in function signatures.
on_class ¤
Add an __init__ method to TypedDict classes if missing.
Source code in packages/griffelib/src/griffe/_internal/extensions/unpack_typeddict.py
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 | |
on_function ¤
Expand **kwargs: Unpack[TypedDict] in function signatures.
Source code in packages/griffelib/src/griffe/_internal/extensions/unpack_typeddict.py
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 | |