Function ¤
Function(
*args: Any,
parameters: Parameters | None = None,
returns: str | Expr | None = None,
decorators: list[Decorator] | None = None,
**kwargs: Any,
)
Bases: Object
flowchart TD
griffe.Function[Function]
griffe._internal.models.Object[Object]
griffe._internal.mixins.ObjectAliasMixin[ObjectAliasMixin]
griffe._internal.mixins.GetMembersMixin[GetMembersMixin]
griffe._internal.mixins.SetMembersMixin[SetMembersMixin]
griffe._internal.mixins.DelMembersMixin[DelMembersMixin]
griffe._internal.mixins.SerializationMixin[SerializationMixin]
griffe._internal.models.Object --> griffe.Function
griffe._internal.mixins.ObjectAliasMixin --> griffe._internal.models.Object
griffe._internal.mixins.GetMembersMixin --> griffe._internal.mixins.ObjectAliasMixin
griffe._internal.mixins.SetMembersMixin --> griffe._internal.mixins.ObjectAliasMixin
griffe._internal.mixins.DelMembersMixin --> griffe._internal.mixins.ObjectAliasMixin
griffe._internal.mixins.SerializationMixin --> griffe._internal.mixins.ObjectAliasMixin
click griffe.Function href "" "griffe.Function"
click griffe._internal.models.Object href "" "griffe._internal.models.Object"
click griffe._internal.mixins.ObjectAliasMixin href "" "griffe._internal.mixins.ObjectAliasMixin"
click griffe._internal.mixins.GetMembersMixin href "" "griffe._internal.mixins.GetMembersMixin"
click griffe._internal.mixins.SetMembersMixin href "" "griffe._internal.mixins.SetMembersMixin"
click griffe._internal.mixins.DelMembersMixin href "" "griffe._internal.mixins.DelMembersMixin"
click griffe._internal.mixins.SerializationMixin href "" "griffe._internal.mixins.SerializationMixin"
The class representing a Python function.
Parameters:
-
(*args¤Any, default:()) –See
griffe.Object. -
(parameters¤Parameters | None, default:None) –The function parameters.
-
(returns¤str | Expr | None, default:None) –The function return annotation.
-
(decorators¤list[Decorator] | None, default:None) –The function decorators, if any.
-
(**kwargs¤Any, default:{}) –See
griffe.Object.
- Guide User guide
- Manipulating APIs
- How-to Supporting custom decorators
- Reference
Methods:
-
__bool__–An object is always true-ish.
-
__delitem__–Delete a member with its name or path.
-
__getitem__–Get a member with its name or path.
-
__len__–The number of members in this object, recursively.
-
__setitem__–Set a member with its name or path.
-
as_dict–Return this function's data as a dictionary.
-
as_json–Return this object's data as a JSON string.
-
del_member–Delete a member with its name or path.
-
filter_members–Filter and return members based on predicates.
-
from_json–Create an instance of this class from a JSON string.
-
get_member–Get a member with its name or path.
-
has_labels–Tell if this object has all the given labels.
-
is_kind–Tell if this object is of the given kind.
-
resolve–Resolve a name within this object's and parents' scope.
-
set_member–Set a member with its name or path.
-
signature–Construct the function signature.
Attributes:
-
aliases(dict[str, Alias]) –The aliases pointing to this object.
-
all_members(dict[str, Object | Alias]) –All members (declared and inherited).
-
analysis(Literal['static', 'dynamic'] | None) –The type of analysis used to load this object.
-
annotation(str | Expr | None) –The type annotation of the returned value.
-
attributes(dict[str, Attribute]) –The attribute members.
-
canonical_path(str) –The full dotted path of this object.
-
classes(dict[str, Class]) –The class members.
-
decorators(list[Decorator]) –The function decorators.
-
deprecated(bool | str | None) –Whether this object is deprecated (boolean or deprecation message).
-
docstring(Docstring | None) –The object docstring.
-
endlineno(int | None) –The ending line number of the object.
-
exports(list[str | ExprName] | None) –The names of the objects exported by this (module) object through the
__all__variable. -
extra(dict[str, dict[str, Any]]) –Namespaced dictionaries storing extra metadata for this object, used by extensions.
-
filepath(Path | list[Path]) –The file path (or directory list for namespace packages) where this object was defined.
-
functions(dict[str, Function]) –The function members.
-
git_info(GitInfo | None) –Git information for this object, if available.
-
has_docstring(bool) –Whether this object has a docstring (empty or not).
-
has_docstrings(bool) –Whether this object or any of its members has a docstring (empty or not).
-
imports(dict[str, str]) –The other objects imported by this object.
-
inherited(bool) –Always false for objects.
-
inherited_members(dict[str, Alias]) –Members that are inherited from base classes.
-
is_alias(bool) –Always false for objects.
-
is_attribute(bool) –Whether this object is an attribute.
-
is_class(bool) –Whether this object is a class.
-
is_class_private(bool) –Whether this object/alias is class-private (starts with
__and is a class member). -
is_collection(bool) –Always false for objects.
-
is_deprecated(bool) –Whether this object is deprecated.
-
is_exported(bool) –Whether this object/alias is exported (listed in
__all__). -
is_function(bool) –Whether this object is a function.
-
is_generic(bool) –Whether this object is generic.
-
is_imported(bool) –Whether this object/alias was imported from another module.
-
is_init_method(bool) –Whether this function is an
__init__method. -
is_init_module(bool) –Whether this object is an
__init__.pymodule. -
is_module(bool) –Whether this object is a module.
-
is_namespace_package(bool) –Whether this object is a namespace package (top folder, no
__init__.py). -
is_namespace_subpackage(bool) –Whether this object is a namespace subpackage.
-
is_package(bool) –Whether this object is a package (top module).
-
is_private(bool) –Whether this object/alias is private (starts with
_) but not special. -
is_public(bool) –Whether this object is considered public.
-
is_special(bool) –Whether this object/alias is special ("dunder" attribute/method, starts and end with
__). -
is_subpackage(bool) –Whether this object is a subpackage.
-
is_type_alias(bool) –Whether this object is a type alias.
-
is_wildcard_exposed(bool) –Whether this object/alias is exposed to wildcard imports.
-
kind–The object kind.
-
labels(set[str]) –The object labels (
property,dataclass, etc.). -
lineno(int | None) –The starting line number of the object.
-
lines(list[str]) –The lines containing the source of this object.
-
lines_collection(LinesCollection) –The lines collection attached to this object or its parents.
-
members(dict[str, Object | Alias]) –The object members (modules, classes, functions, attributes, type aliases).
-
module(Module) –The parent module of this object.
-
modules(dict[str, Module]) –The module members.
-
modules_collection(ModulesCollection) –The modules collection attached to this object or its parents.
-
name(str) –The object name.
-
overloads(list[Function] | None) –The overloaded signatures of this function.
-
package(Module) –The absolute top module (the package) of this object.
-
parameters(Parameters) –The function parameters.
-
parent(Module | Class | None) –The parent of the object (none if top module).
-
path(str) –The dotted path of this object.
-
public(bool | None) –Whether this object is public.
-
relative_filepath(Path) –The file path where this object was defined, relative to the current working directory.
-
relative_package_filepath(Path) –The file path where this object was defined, relative to the top module path.
-
returns(str | Expr | None) –The function return type annotation.
-
runtime(bool) –Whether this object is available at runtime.
-
source(str) –The source code of this object.
-
source_link(str | None) –Source link for this object, if available.
-
type_aliases(dict[str, TypeAlias]) –The type alias members.
-
type_parameters(TypeParameters) –The object type parameters.
Source code in src/griffe/_internal/models.py
2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 | |
aliases instance-attribute ¤
The aliases pointing to this object.
- Guide User guide Manipulating APIs Navigating APIs
all_members property ¤
All members (declared and inherited).
This method is part of the consumer API: do not use when producing Griffe trees!
- Guide User guide Manipulating APIs Navigating APIs Moving down: members
analysis instance-attribute ¤
The type of analysis used to load this object.
None means the object was created manually.
attributes property ¤
The attribute members.
This method is part of the consumer API: do not use when producing Griffe trees!
- Guide User guide Manipulating APIs Navigating APIs Moving down: members
canonical_path property ¤
canonical_path: str
The full dotted path of this object.
The canonical path is the path where the object was defined (not imported).
See also: path.
classes property ¤
The class members.
This method is part of the consumer API: do not use when producing Griffe trees!
- Guide User guide Manipulating APIs Navigating APIs Moving down: members
decorators instance-attribute ¤
decorators: list[Decorator] = decorators or []
The function decorators.
- Guide User guide Manipulating APIs Navigating APIs Model-specific fields Functions
deprecated instance-attribute ¤
Whether this object is deprecated (boolean or deprecation message).
- Extensions Official griffe-warnings-deprecated
- Guide User guide Manipulating APIs Navigating APIs Object visibility
docstring instance-attribute ¤
The object docstring.
See also: has_docstring, has_docstrings.
- Guide User guide Manipulating APIs Navigating APIs Docstrings
- Reference Python API
endlineno instance-attribute ¤
exports instance-attribute ¤
The names of the objects exported by this (module) object through the __all__ variable.
Exports can contain string (object names) or resolvable names, like other lists of exports coming from submodules:
from .submodule import __all__ as submodule_all
__all__ = ["hello", *submodule_all]
Exports get expanded by the loader before it expands wildcards and resolves aliases.
See also: GriffeLoader.expand_exports.
- Guide User guide Manipulating APIs Navigating APIs Imports/exports
- Reference Python API Loaders
GriffeLoaderexpand_exports
extra instance-attribute ¤
Namespaced dictionaries storing extra metadata for this object, used by extensions.
filepath property ¤
The file path (or directory list for namespace packages) where this object was defined.
See also: relative_filepath, relative_package_filepath.
Examples:
>>> import griffe
>>> markdown = griffe.load("markdown")
>>> markdown.filepath
PosixPath('~/project/.venv/lib/python3.11/site-packages/markdown/__init__.py')
- Guide User guide Manipulating APIs Navigating APIs Object location Source
- Reference Python API
functions property ¤
The function members.
This method is part of the consumer API: do not use when producing Griffe trees!
- Guide User guide Manipulating APIs Navigating APIs Moving down: members
git_info property writable ¤
git_info: GitInfo | None
Git information for this object, if available.
- Guide User guide Manipulating APIs Loading APIs Source information
has_docstring property ¤
has_docstring: bool
Whether this object has a docstring (empty or not).
See also: docstring, has_docstrings.
- Guide User guide Manipulating APIs Navigating APIs Docstrings
- Reference Python API
has_docstrings property ¤
has_docstrings: bool
Whether this object or any of its members has a docstring (empty or not).
Inherited members are not considered. Imported members are not considered, unless they are also public.
See also: docstring, has_docstring.
- Guide User guide Manipulating APIs Navigating APIs Docstrings
- Reference Python API
imports instance-attribute ¤
The other objects imported by this object.
Keys are the names within the object (from ... import ... as AS_NAME), while the values are the actual names of the objects (from ... import REAL_NAME as ...).
- Guide User guide Manipulating APIs Navigating APIs Imports/exports
inherited class-attribute instance-attribute ¤
inherited: bool = False
Always false for objects.
Only aliases can be marked as inherited.
inherited_members property ¤
Members that are inherited from base classes.
This method is part of the consumer API: do not use when producing Griffe trees!
See also: members.
is_alias class-attribute instance-attribute ¤
is_alias: bool = False
Always false for objects.
- Guide User guide Manipulating APIs Navigating APIs
- Reference Python API
is_attribute property ¤
is_attribute: bool
Whether this object is an attribute.
See also: is_module. is_class, is_function, is_type_alias, is_alias, is_kind.
- Guide User guide Manipulating APIs Navigating APIs Object kind
- Reference Python API
is_class property ¤
is_class: bool
Whether this object is a class.
See also: is_module. is_function, is_attribute, is_type_alias, is_alias, is_kind.
- Guide User guide Manipulating APIs Navigating APIs Object kind
- Reference Python API
is_class_private property ¤
is_class_private: bool
Whether this object/alias is class-private (starts with __ and is a class member).
- Guide User guide Manipulating APIs Navigating APIs Object visibility
is_collection class-attribute instance-attribute ¤
is_collection: bool = False
Always false for objects.
is_deprecated property ¤
is_deprecated: bool
Whether this object is deprecated.
- Guide User guide Manipulating APIs Navigating APIs Object visibility
is_exported property ¤
is_exported: bool
Whether this object/alias is exported (listed in __all__).
- Changelog 0.46.0 - 2024-06-16 Deprecations
- Guide User guide Manipulating APIs Navigating APIs Imports/exports
is_function property ¤
is_function: bool
Whether this object is a function.
See also: is_module. is_class, is_attribute, is_type_alias, is_alias, is_kind.
- Guide User guide Manipulating APIs Navigating APIs Object kind
- Reference Python API
is_imported property ¤
is_imported: bool
Whether this object/alias was imported from another module.
- Guide User guide Manipulating APIs Navigating APIs Imports/exports
- Reference Python API Models
Aliasimports
is_init_module property ¤
is_init_module: bool
is_module property ¤
is_module: bool
Whether this object is a module.
See also: is_init_module. is_class, is_function, is_attribute, is_type_alias, is_alias, is_kind.
- Guide User guide Manipulating APIs Navigating APIs Object kind
- Reference Python API
is_namespace_package property ¤
is_namespace_package: bool
Whether this object is a namespace package (top folder, no __init__.py).
See also: is_namespace_subpackage.
is_namespace_subpackage property ¤
is_namespace_subpackage: bool
Whether this object is a namespace subpackage.
See also: is_namespace_package.
is_package property ¤
is_package: bool
is_private property ¤
is_private: bool
Whether this object/alias is private (starts with _) but not special.
- Guide User guide Manipulating APIs Navigating APIs Object visibility
is_public property ¤
is_public: bool
Whether this object is considered public.
In modules, developers can mark objects as public thanks to the __all__ variable. In classes however, there is no convention or standard to do so.
Therefore, to decide whether an object is public, we follow this algorithm:
- If the object's
publicattribute is set (boolean), return its value. - If the object is listed in its parent's (a module)
__all__attribute, it is public. - If the parent (module) defines
__all__and the object is not listed in, it is private. - If the object has a private name, it is private.
- If the object was imported from another module, it is private.
- Otherwise, the object is public.
- Changelog 0.46.0 - 2024-06-16 Deprecations
- Guide User guide Manipulating APIs Navigating APIs Object visibility
is_special property ¤
is_special: bool
Whether this object/alias is special ("dunder" attribute/method, starts and end with __).
- Guide User guide Manipulating APIs Navigating APIs Object visibility
is_subpackage property ¤
is_subpackage: bool
is_type_alias property ¤
is_type_alias: bool
Whether this object is a type alias.
See also: is_module. is_class, is_function, is_attribute, is_alias, is_kind.
- Guide User guide Manipulating APIs Navigating APIs Object kind
- Reference Python API
is_wildcard_exposed property ¤
is_wildcard_exposed: bool
Whether this object/alias is exposed to wildcard imports.
To be exposed to wildcard imports, an object/alias must:
- be available at runtime
- have a module as parent
- be listed in
__all__if__all__is defined - or not be private (having a name starting with an underscore)
Special case for Griffe trees: a submodule is only exposed if its parent imports it.
Returns:
-
bool–True or False.
- Guide User guide Manipulating APIs Navigating APIs Imports/exports
labels instance-attribute ¤
lineno instance-attribute ¤
lines property ¤
The lines containing the source of this object.
See also: lines_collection, source.
- Guide User guide Manipulating APIs Navigating APIs Object location Source
- Reference Python API
lines_collection property ¤
lines_collection: LinesCollection
The lines collection attached to this object or its parents.
Raises:
-
ValueError–When no modules collection can be found in the object or its parents.
members instance-attribute ¤
The object members (modules, classes, functions, attributes, type aliases).
See also: inherited_members, get_member, set_member, filter_members.
- Guide User guide Manipulating APIs Navigating APIs Moving down: members
- Reference Python API
module property ¤
module: Module
The parent module of this object.
See also: package.
Examples:
>>> import griffe
>>> markdown = griffe.load("markdown")
>>> markdown["core.Markdown.references"].module
Module(PosixPath('~/project/.venv/lib/python3.11/site-packages/markdown/core.py'))
>>> # The `module` of a module is itself.
>>> markdown["core"].module
Module(PosixPath('~/project/.venv/lib/python3.11/site-packages/markdown/core.py'))
Raises:
-
ValueError–When the object is not a module and does not have a parent.
modules property ¤
The module members.
This method is part of the consumer API: do not use when producing Griffe trees!
- Guide User guide Manipulating APIs Navigating APIs Moving down: members
modules_collection property ¤
modules_collection: ModulesCollection
The modules collection attached to this object or its parents.
Raises:
-
ValueError–When no modules collection can be found in the object or its parents.
- Guide User guide Manipulating APIs Navigating APIs Moving up: parents
overloads instance-attribute ¤
The overloaded signatures of this function.
- Guide User guide Manipulating APIs Navigating APIs Model-specific fields Functions
package property ¤
package: Module
The absolute top module (the package) of this object.
See also: module.
Examples:
>>> import griffe
>>> markdown = griffe.load("markdown")
>>> markdown["core.Markdown.references"].package
Module(PosixPath('~/project/.venv/lib/python3.11/site-packages/markdown/__init__.py'))
parameters instance-attribute ¤
parameters: Parameters = parameters or Parameters()
The function parameters.
- Guide User guide Manipulating APIs Navigating APIs Model-specific fields Functions
parent instance-attribute ¤
The parent of the object (none if top module).
- Guide User guide Manipulating APIs Navigating APIs Moving up: parents
path property ¤
path: str
The dotted path of this object.
On regular objects (not aliases), the path is the canonical path.
See also: canonical_path.
Examples:
>>> import griffe
>>> markdown = griffe.load("markdown")
>>> markdown["core.Markdown.references"].path
'markdown.core.Markdown.references'
public instance-attribute ¤
public: bool | None = None
Whether this object is public.
- Guide User guide Manipulating APIs Navigating APIs Object visibility
relative_filepath property ¤
relative_filepath: Path
The file path where this object was defined, relative to the current working directory.
If this object's file path is not relative to the current working directory, return its absolute path.
See also: filepath, relative_package_filepath.
Raises:
-
ValueError–When the relative path could not be computed.
- Guide User guide Manipulating APIs Navigating APIs Object location Source
- Reference Python API
relative_package_filepath property ¤
relative_package_filepath: Path
The file path where this object was defined, relative to the top module path.
See also: filepath, relative_filepath.
Raises:
-
ValueError–When the relative path could not be computed.
- Guide User guide Manipulating APIs Navigating APIs Object location Source
- Reference Python API
returns instance-attribute ¤
The function return type annotation.
- Guide User guide Manipulating APIs Navigating APIs Model-specific fields Functions
runtime instance-attribute ¤
Whether this object is available at runtime.
Typically, type-guarded objects (under an if TYPE_CHECKING condition) are not available at runtime.
source property ¤
source: str
The source code of this object.
See also: lines, lines_collection.
- Guide User guide Manipulating APIs Navigating APIs Object location Source
- Reference Python API
source_link property writable ¤
source_link: str | None
Source link for this object, if available.
- Guide User guide Manipulating APIs Loading APIs Source information
type_aliases property ¤
The type alias members.
This method is part of the consumer API: do not use when producing Griffe trees!
- Guide User guide Manipulating APIs Navigating APIs Moving down: members
type_parameters instance-attribute ¤
type_parameters: TypeParameters = (
type_parameters or TypeParameters()
)
The object type parameters.
- Guide User guide Manipulating APIs Navigating APIs Model-specific fields
__bool__ ¤
__bool__() -> bool
An object is always true-ish.
Source code in src/griffe/_internal/models.py
717 718 719 | |
__delitem__ ¤
Delete a member with its name or path.
This method is part of the consumer API: do not use when producing Griffe trees!
Members will be looked up in both declared members and inherited ones, triggering computation of the latter.
Parameters:
Examples:
>>> del griffe_object["foo"]
>>> del griffe_object["path.to.bar"]
>>> del griffe_object[("path", "to", "qux")]
Source code in src/griffe/_internal/mixins.py
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 | |
__getitem__ ¤
Get a member with its name or path.
This method is part of the consumer API: do not use when producing Griffe trees!
Members will be looked up in both declared members and inherited ones, triggering computation of the latter.
Parameters:
Examples:
>>> foo = griffe_object["foo"]
>>> bar = griffe_object["path.to.bar"]
>>> qux = griffe_object[("path", "to", "qux")]
Source code in src/griffe/_internal/mixins.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
__len__ ¤
__len__() -> int
The number of members in this object, recursively.
Source code in src/griffe/_internal/models.py
721 722 723 | |
__setitem__ ¤
Set a member with its name or path.
This method is part of the consumer API: do not use when producing Griffe trees!
Parameters:
-
(key¤str | Sequence[str]) –The name or path of the member.
-
(value¤Object | Alias) –The member.
Examples:
>>> griffe_object["foo"] = foo
>>> griffe_object["path.to.bar"] = bar
>>> griffe_object[("path", "to", "qux")] = qux
Source code in src/griffe/_internal/mixins.py
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 | |
as_dict ¤
Return this function's data as a dictionary.
See also: as_json.
Parameters:
Returns:
Source code in src/griffe/_internal/models.py
2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 | |
as_json ¤
Return this object's data as a JSON string.
Parameters:
-
(full¤bool, default:False) –Whether to return full info, or just base info.
-
(**kwargs¤Any, default:{}) –Additional serialization options passed to encoder.
Returns:
-
str–A JSON string.
Source code in src/griffe/_internal/mixins.py
215 216 217 218 219 220 221 222 223 224 225 226 227 | |
del_member ¤
Delete a member with its name or path.
This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).
Members will be looked up in declared members only, not inherited ones.
Parameters:
Examples:
>>> griffe_object.del_member("foo")
>>> griffe_object.del_member("path.to.bar")
>>> griffe_object.del_member(("path", "to", "qux"))
Source code in src/griffe/_internal/mixins.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
filter_members ¤
Filter and return members based on predicates.
See also: members.
Parameters:
-
(*predicates¤Callable[[Object | Alias], bool], default:()) –A list of predicates, i.e. callables accepting a member as argument and returning a boolean.
Returns:
Source code in src/griffe/_internal/models.py
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 | |
from_json classmethod ¤
from_json(json_string: str, **kwargs: Any) -> _ObjType
Create an instance of this class from a JSON string.
Parameters:
-
(json_string¤str) –JSON to decode into Object.
-
(**kwargs¤Any, default:{}) –Additional options passed to decoder.
Returns:
-
_ObjType–An Object instance.
Raises:
-
TypeError–When the json_string does not represent and object of the class from which this classmethod has been called.
- Guide User guide Manipulating APIs Serializing APIs Python API
- Reference
Source code in src/griffe/_internal/mixins.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
get_member ¤
Get a member with its name or path.
This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).
Members will be looked up in declared members only, not inherited ones.
Parameters:
Examples:
>>> foo = griffe_object["foo"]
>>> bar = griffe_object["path.to.bar"]
>>> bar = griffe_object[("path", "to", "bar")]
Source code in src/griffe/_internal/mixins.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
has_labels ¤
Tell if this object has all the given labels.
See also: labels.
Parameters:
Returns:
-
bool–True or False.
Source code in src/griffe/_internal/models.py
954 955 956 957 958 959 960 961 962 963 964 965 | |
is_kind ¤
Tell if this object is of the given kind.
See also: is_module, is_class, is_function, is_attribute, is_type_alias, is_alias.
Parameters:
Raises:
-
ValueError–When an empty set is given as argument.
Returns:
-
bool–True or False.
- Guide User guide Manipulating APIs Navigating APIs Object kind
- Reference Python API
Source code in src/griffe/_internal/models.py
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 | |
resolve ¤
Resolve a name within this object's and parents' scope.
Parameters:
Raises:
-
NameResolutionError–When the name could not be resolved.
Returns:
-
str–The resolved name.
Source code in src/griffe/_internal/models.py
2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 | |
set_member ¤
Set a member with its name or path.
This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).
Parameters:
-
(key¤str | Sequence[str]) –The name or path of the member.
-
(value¤Object | Alias) –The member.
Examples:
>>> griffe_object.set_member("foo", foo)
>>> griffe_object.set_member("path.to.bar", bar)
>>> griffe_object.set_member(("path", "to", "qux"), qux)
Source code in src/griffe/_internal/mixins.py
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 | |
signature ¤
signature(
*, return_type: bool = True, name: str | None = None
) -> str
Construct the function signature.
Parameters:
-
(return_type¤bool, default:True) –Whether to include the return type in the signature.
-
(name¤str | None, default:None) –The name of the function to use in the signature.
Returns:
-
str–A string representation of the function signature.
Source code in src/griffe/_internal/models.py
2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 | |
Parameters ¤
Parameters(*parameters: Parameter)
This class is a container for parameters.
It allows to get parameters using their position (index) or their name:
>>> parameters = Parameters(Parameter("hello"))
>>> parameters[0] is parameters["hello"]
True
See also: Parameter.
Parameters:
- Guide User guide Manipulating APIs Navigating APIs Model-specific fields
- Reference
Methods:
-
__contains__–Whether a parameter with the given name is present.
-
__delitem__–Delete a parameter by index or name.
-
__getitem__–Get a parameter by index or name.
-
__iter__–Iterate over the parameters, in order.
-
__len__–The number of parameters.
-
__setitem__–Set a parameter by index or name.
-
add–Add a parameter to the container.
Source code in src/griffe/_internal/models.py
308 309 310 311 312 313 314 | |
__contains__ ¤
__contains__(param_name: str)
Whether a parameter with the given name is present.
Source code in src/griffe/_internal/models.py
362 363 364 365 366 367 368 | |
__delitem__ ¤
Delete a parameter by index or name.
Source code in src/griffe/_internal/models.py
342 343 344 345 346 347 348 349 350 351 352 | |
__getitem__ ¤
Get a parameter by index or name.
Source code in src/griffe/_internal/models.py
319 320 321 322 323 324 325 326 327 | |
__iter__ ¤
__iter__()
Iterate over the parameters, in order.
Source code in src/griffe/_internal/models.py
358 359 360 | |
__len__ ¤
__len__()
The number of parameters.
Source code in src/griffe/_internal/models.py
354 355 356 | |
__setitem__ ¤
Set a parameter by index or name.
Source code in src/griffe/_internal/models.py
329 330 331 332 333 334 335 336 337 338 339 340 | |
add ¤
Add a parameter to the container.
Parameters:
Raises:
-
ValueError–When a parameter with the same name is already present.
Source code in src/griffe/_internal/models.py
370 371 372 373 374 375 376 377 378 379 380 381 | |
Parameter ¤
Parameter(
name: str,
*,
annotation: str | Expr | None = None,
kind: ParameterKind | None = None,
default: str | Expr | None = None,
docstring: Docstring | None = None,
)
This class represent a function parameter.
See also: Parameters.
Parameters:
-
(name¤str) –The parameter name, without leading stars (
*or**). -
(annotation¤str | Expr | None, default:None) –The parameter annotation, if any.
-
(kind¤ParameterKind | None, default:None) –The parameter kind.
-
(default¤str | Expr | None, default:None) –The parameter default, if any.
-
(docstring¤Docstring | None, default:None) –The parameter docstring.
Methods:
-
__eq__–Parameters are equal if all their attributes except
docstringandfunctionare equal. -
as_dict–Return this parameter's data as a dictionary.
Attributes:
-
annotation(str | Expr | None) –The parameter type annotation.
-
default(str | Expr | None) –The parameter default value.
-
docstring(Docstring | None) –The parameter docstring.
-
function(Function | None) –The parent function of the parameter.
-
kind(ParameterKind | None) –The parameter kind.
-
name(str) –The parameter name.
-
required(bool) –Whether this parameter is required.
Source code in src/griffe/_internal/models.py
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 | |
annotation instance-attribute ¤
annotation: str | Expr | None = annotation
The parameter type annotation.
function instance-attribute ¤
function: Function | None = None
The parent function of the parameter.
__eq__ ¤
Parameters are equal if all their attributes except docstring and function are equal.
Source code in src/griffe/_internal/models.py
258 259 260 261 262 263 264 265 266 267 | |
as_dict ¤
Return this parameter's data as a dictionary.
Parameters:
Returns:
Source code in src/griffe/_internal/models.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
ParameterKind ¤
flowchart TD
griffe.ParameterKind[ParameterKind]
click griffe.ParameterKind href "" "griffe.ParameterKind"
Enumeration of the different parameter kinds.
Attributes:
-
keyword_only–Keyword-only parameter.
-
positional_only–Positional-only parameter.
-
positional_or_keyword–Positional or keyword parameter.
-
var_keyword–Variadic keyword parameter.
-
var_positional–Variadic positional parameter.
keyword_only class-attribute instance-attribute ¤
keyword_only = 'keyword-only'
Keyword-only parameter.
positional_only class-attribute instance-attribute ¤
positional_only = 'positional-only'
Positional-only parameter.
positional_or_keyword class-attribute instance-attribute ¤
positional_or_keyword = 'positional or keyword'
Positional or keyword parameter.
var_keyword class-attribute instance-attribute ¤
var_keyword = 'variadic keyword'
Variadic keyword parameter.
var_positional class-attribute instance-attribute ¤
var_positional = 'variadic positional'
Variadic positional parameter.
ParametersType module-attribute ¤
Type alias for the list of parameters of a function.
Decorator ¤
This class represents decorators.
Parameters:
-
(value¤str | Expr) –The decorator code.
-
(lineno¤int | None) –The starting line number.
-
(endlineno¤int | None) –The ending line number.
- Guide User guide Manipulating APIs Navigating APIs Model-specific fields
- Reference
griffe Models
Methods:
-
as_dict–Return this decorator's data as a dictionary.
Attributes:
-
callable_path(str) –The path of the callable used as decorator.
-
endlineno(int | None) –The ending line number of the decorator.
-
lineno(int | None) –The starting line number of the decorator.
-
value(str | Expr) –The decorator value (as a Griffe expression or string).
Source code in src/griffe/_internal/models.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
endlineno instance-attribute ¤
The ending line number of the decorator.
value instance-attribute ¤
The decorator value (as a Griffe expression or string).
as_dict ¤
Return this decorator's data as a dictionary.
Parameters:
Returns:
Source code in src/griffe/_internal/models.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |