dataclasses ¤
This module contains the data classes that represent Python objects.
The different objects are modules, classes, functions, and attribute (variables like module/class/instance attributes).
Classes:
-
Alias
–This class represents an alias, or indirection, to an object declared in another module.
-
Attribute
–The class representing a Python module/class/instance attribute.
-
Class
–The class representing a Python class.
-
Decorator
–This class represents decorators.
-
Docstring
–This class represents docstrings.
-
Function
–The class representing a Python function.
-
Kind
–Enumeration of the different object kinds.
-
Module
–The class representing a Python module.
-
Object
–An abstract class representing a Python object.
-
Parameter
–This class represent a function parameter.
-
ParameterKind
–Enumeration of the different parameter kinds.
-
Parameters
–This class is a container for parameters.
Alias ¤
Alias(
name: str,
target: str | Object | Alias,
*,
lineno: int | None = None,
endlineno: int | None = None,
runtime: bool = True,
parent: Module | Class | Alias | None = None,
inherited: bool = False
)
flowchart TD
griffe.dataclasses.Alias[Alias]
griffe.mixins.ObjectAliasMixin[ObjectAliasMixin]
griffe.mixins.GetMembersMixin[GetMembersMixin]
griffe.mixins.SetMembersMixin[SetMembersMixin]
griffe.mixins.DelMembersMixin[DelMembersMixin]
griffe.mixins.SerializationMixin[SerializationMixin]
griffe.mixins.ObjectAliasMixin --> griffe.dataclasses.Alias
griffe.mixins.GetMembersMixin --> griffe.mixins.ObjectAliasMixin
griffe.mixins.SetMembersMixin --> griffe.mixins.ObjectAliasMixin
griffe.mixins.DelMembersMixin --> griffe.mixins.ObjectAliasMixin
griffe.mixins.SerializationMixin --> griffe.mixins.ObjectAliasMixin
click griffe.dataclasses.Alias href "" "griffe.dataclasses.Alias"
click griffe.mixins.ObjectAliasMixin href "" "griffe.mixins.ObjectAliasMixin"
click griffe.mixins.GetMembersMixin href "" "griffe.mixins.GetMembersMixin"
click griffe.mixins.SetMembersMixin href "" "griffe.mixins.SetMembersMixin"
click griffe.mixins.DelMembersMixin href "" "griffe.mixins.DelMembersMixin"
click griffe.mixins.SerializationMixin href "" "griffe.mixins.SerializationMixin"
This class represents an alias, or indirection, to an object declared in another module.
Aliases represent objects that are in the scope of a module or class, but were imported from another module.
They behave almost exactly like regular objects, to a few exceptions:
- line numbers are those of the alias, not the target
- the path is the alias path, not the canonical one
- the name can be different from the target's
- if the target can be resolved, the kind is the target's kind
- if the target cannot be resolved, the kind becomes Kind.ALIAS
Parameters:
-
name
(str
) –The alias name.
-
target
(str | Object | Alias
) –If it's a string, the target resolution is delayed until accessing the target property. If it's an object, or even another alias, the target is immediately set.
-
lineno
(int | None
, default:None
) –The alias starting line number.
-
endlineno
(int | None
, default:None
) –The alias ending line number.
-
runtime
(bool
, default:True
) –Whether this alias is present at runtime or not.
-
parent
(Module | Class | Alias | None
, default:None
) –The alias parent.
-
inherited
(bool
, default:False
) –Whether this alias wraps an inherited member.
Methods:
-
__delitem__
–Delete a member with its name or path.
-
__getitem__
–Get a member with its name or path.
-
__setitem__
–Set a member with its name or path.
-
as_dict
–Return this alias' data as a dictionary.
-
as_json
–Return this target'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_exported
–Tell if this object/alias is implicitely exported by its parent.
-
is_kind
–Tell if this object is of the given kind.
-
is_public
–Whether this object is considered public.
-
member_is_exported
–Whether a member of this object is "exported".
-
mro
–Return a list of classes in order corresponding to Python's MRO.
-
resolve
–Resolve a name within this object's and parents' scope.
-
resolve_target
–Resolve the target.
-
set_member
–Set a member with its name or path.
Attributes:
-
alias_endlineno
(int | None
) –The ending line number of the alias.
-
alias_lineno
(int | None
) –The starting line number of the alias.
-
aliases
(dict[str, Alias]
) –The aliases pointing to this object.
-
all_members
(dict[str, Object | Alias]
) –All members (declared and inherited).
-
annotation
(str | Expr | None
) –The attribute type annotation.
-
attributes
(dict[str, Attribute]
) –The attribute members.
-
bases
(list[Expr | str]
) –The class bases.
-
canonical_path
(str
) –The full dotted path of this object.
-
classes
(dict[str, Class]
) –The class members.
-
decorators
(list[Decorator]
) –The class/function decorators.
-
deleter
(Function | None
) –The deleter linked to this function (property).
-
docstring
(Docstring | None
) –The target docstring.
-
endlineno
(int | None
) –The ending line number of the target object.
-
exports
(set[str] | list[str | ExprName] | None
) –The names of the objects exported by this (module) object through the
__all__
variable. -
extra
(dict
) –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.
-
final_target
(Object
) –The final, resolved target, if possible.
-
functions
(dict[str, Function]
) –The function members.
-
has_docstring
(bool
) –Whether this alias' target has a non-empty docstring.
-
has_docstrings
(bool
) –Whether this alias' target or any of its members has a non-empty docstring.
-
imports
(dict[str, str]
) –The other objects imported by this alias' target.
-
imports_future_annotations
(bool
) –Whether this module import future annotations.
-
inherited
(bool
) –Whether this alias represents an inherited member.
-
inherited_members
(dict[str, Alias]
) –Members that are inherited from base classes.
-
is_attribute
(bool
) –Whether this object is an attribute.
-
is_class
(bool
) –Whether this object is a class.
-
is_explicitely_exported
(bool
) –Whether this object/alias is explicitely exported by its parent.
-
is_function
(bool
) –Whether this object is a function.
-
is_implicitely_exported
(bool
) –Whether this object/alias is implicitely exported by its parent.
-
is_init_module
(bool
) –Whether this module is an
__init__.py
module. -
is_module
(bool
) –Whether this object is a module.
-
is_namespace_package
(bool
) –Whether this module is a namespace package (top folder, no
__init__.py
). -
is_namespace_subpackage
(bool
) –Whether this module is a namespace subpackage.
-
is_package
(bool
) –Whether this module is a package (top module).
-
is_subpackage
(bool
) –Whether this module is a subpackage.
-
kind
(Kind
) –The target's kind, or
Kind.ALIAS
if the target cannot be resolved. -
labels
(set[str]
) –The target labels (
property
,dataclass
, etc.). -
lineno
(int | None
) –The starting line number of the target 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 target's members (modules, classes, functions, attributes).
-
module
(Module
) –The parent module of this object.
-
modules
(dict[str, Module]
) –The module members.
-
modules_collection
(ModulesCollection
) –The modules collection attached to the alias parents.
-
name
(str
) –The alias name.
-
overloads
(dict[str, list[Function]] | list[Function] | None
) –The overloaded signatures declared in this class/module or for this function.
-
package
(Module
) –The absolute top module (the package) of this object.
-
parameters
(Parameters
) –The parameters of the current function or
__init__
method for classes. -
parent
(Module | Class | Alias | None
) –The parent of this alias.
-
path
(str
) –The dotted path / import path of this object.
-
public
(bool | None
) –Whether this alias 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.
-
resolved
(bool
) –Whether this alias' target is resolved.
-
resolved_bases
(list[Object]
) –Resolved class bases.
-
returns
(str | Expr | None
) –The function return type annotation.
-
runtime
(bool
) –Whether this alias is available at runtime.
-
setter
(Function | None
) –The setter linked to this function (property).
-
source
(str
) –The source code of this object.
-
target
(Object | Alias
) –The resolved target (actual object), if possible.
-
target_path
(str
) –The path of this alias' target.
-
value
(str | Expr | None
) –The attribute value.
-
wildcard
(str | None
) –The module on which the wildcard import is performed (if any).
alias_endlineno instance-attribute
¤
The ending line number of the alias.
alias_lineno instance-attribute
¤
The starting line number of the alias.
all_members property
¤
All members (declared and inherited).
This method is part of the consumer API: do not use when producing Griffe trees!
attributes property
¤
The attribute members.
This method is part of the consumer API: do not use when producing Griffe trees!
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).
classes property
¤
The class members.
This method is part of the consumer API: do not use when producing Griffe trees!
exports property
¤
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.
extra property
¤
extra: dict
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.
final_target property
¤
final_target: Object
The final, resolved target, if possible.
This will iterate through the targets until a non-alias object is found.
functions property
¤
The function members.
This method is part of the consumer API: do not use when producing Griffe trees!
has_docstrings property
¤
has_docstrings: bool
Whether this alias' target or any of its members has a non-empty docstring.
imports property
¤
The other objects imported by this alias' target.
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 ...
).
imports_future_annotations property
¤
imports_future_annotations: bool
Whether this module import future annotations.
inherited instance-attribute
¤
Whether this alias represents an inherited member.
inherited_members cached
property
¤
Members that are inherited from base classes.
Each inherited member of the target will be wrapped in an alias, to preserve correct object access paths.
This method is part of the consumer API: do not use when producing Griffe trees!
is_explicitely_exported property
¤
is_explicitely_exported: bool
Whether this object/alias is explicitely exported by its parent.
is_implicitely_exported property
¤
is_implicitely_exported: bool
Whether this object/alias is implicitely exported by its parent.
is_namespace_package property
¤
is_namespace_package: bool
Whether this module is a namespace package (top folder, no __init__.py
).
is_namespace_subpackage property
¤
is_namespace_subpackage: bool
Whether this module is a namespace subpackage.
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 cached
property
¤
The target's members (modules, classes, functions, attributes).
module property
¤
module: Module
The parent module of this object.
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!
modules_collection property
¤
modules_collection: ModulesCollection
The modules collection attached to the alias parents.
overloads property
writable
¤
The overloaded signatures declared in this class/module or for this function.
parameters property
¤
parameters: Parameters
The parameters of the current function or __init__
method for classes.
This property can fetch inherited members, and therefore is part of the consumer API: do not use when producing Griffe trees!
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.
Raises:
-
ValueError
–When the relative path could not be computed.
relative_package_filepath property
¤
relative_package_filepath: Path
The file path where this object was defined, relative to the top module path.
Raises:
-
ValueError
–When the relative path could not be computed.
resolved_bases property
¤
Resolved class bases.
This method is part of the consumer API: do not use when producing Griffe trees!
target property
writable
¤
The resolved target (actual object), if possible.
Upon accessing this property, if the target is not already resolved, a lookup is done using the modules collection to find the target.
wildcard property
¤
wildcard: str | None
The module on which the wildcard import is performed (if any).
__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")]
__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")]
__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:
Examples:
>>> griffe_object["foo"] = foo
>>> griffe_object["path.to.bar"] = bar
>>> griffe_object[("path", "to", "qux")] = qux
as_dict ¤
as_json ¤
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"))
filter_members ¤
from_json classmethod
¤
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.
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")]
has_labels ¤
is_exported ¤
is_kind ¤
is_public ¤
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
public
attribute is set (boolean), return its value. - In strict mode, the object is public only if it is explicitely exported (listed in
__all__
). Strict mode should only be used for module members. - Otherwise, if name checks are enabled, the object is private if its name starts with an underscore.
- Otherwise, if the object is an alias, and is neither inherited from a base class, nor a member of a parent alias, it is not public.
- Otherwise, the object is public.
member_is_exported ¤
Whether a member of this object is "exported".
By exported, we mean that the object is included in the __all__
attribute of its parent module or class. When __all__
is not defined, we consider the member to be implicitely exported, unless it's a module and it was not imported, and unless it's not defined at runtime.
Parameters:
-
member
(Object | Alias
) –The member to verify.
-
explicitely
(bool
, default:True
) –Whether to only return True when
__all__
is defined.
Returns:
-
bool
–True or False.
resolve ¤
Resolve a name within this object's and parents' scope.
Parameters:
-
name
(str
) –The name to resolve.
Raises:
-
NameResolutionError
–When the name could not be resolved.
Returns:
-
str
–The resolved name.
resolve_target ¤
resolve_target() -> None
Resolve the target.
Raises:
-
AliasResolutionError
–When the target cannot be resolved. It happens when the target does not exist, or could not be loaded (unhandled dynamic object?), or when the target is from a module that was not loaded and added to the collection.
-
CyclicAliasError
–When the resolved target is the alias itself.
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:
Examples:
>>> griffe_object.set_member("foo", foo)
>>> griffe_object.set_member("path.to.bar", bar)
>>> griffe_object.set_member(("path", "to", "qux", qux)
Attribute ¤
Attribute(
*args: Any,
value: str | Expr | None = None,
annotation: str | Expr | None = None,
**kwargs: Any
)
flowchart TD
griffe.dataclasses.Attribute[Attribute]
griffe.dataclasses.Object[Object]
griffe.mixins.ObjectAliasMixin[ObjectAliasMixin]
griffe.mixins.GetMembersMixin[GetMembersMixin]
griffe.mixins.SetMembersMixin[SetMembersMixin]
griffe.mixins.DelMembersMixin[DelMembersMixin]
griffe.mixins.SerializationMixin[SerializationMixin]
griffe.dataclasses.Object --> griffe.dataclasses.Attribute
griffe.mixins.ObjectAliasMixin --> griffe.dataclasses.Object
griffe.mixins.GetMembersMixin --> griffe.mixins.ObjectAliasMixin
griffe.mixins.SetMembersMixin --> griffe.mixins.ObjectAliasMixin
griffe.mixins.DelMembersMixin --> griffe.mixins.ObjectAliasMixin
griffe.mixins.SerializationMixin --> griffe.mixins.ObjectAliasMixin
click griffe.dataclasses.Attribute href "" "griffe.dataclasses.Attribute"
click griffe.dataclasses.Object href "" "griffe.dataclasses.Object"
click griffe.mixins.ObjectAliasMixin href "" "griffe.mixins.ObjectAliasMixin"
click griffe.mixins.GetMembersMixin href "" "griffe.mixins.GetMembersMixin"
click griffe.mixins.SetMembersMixin href "" "griffe.mixins.SetMembersMixin"
click griffe.mixins.DelMembersMixin href "" "griffe.mixins.DelMembersMixin"
click griffe.mixins.SerializationMixin href "" "griffe.mixins.SerializationMixin"
The class representing a Python module/class/instance attribute.
Parameters:
-
*args
(Any
, default:()
) – -
value
(str | Expr | None
, default:None
) –The attribute value, if any.
-
annotation
(str | Expr | None
, default:None
) –The attribute annotation, if any.
-
**kwargs
(Any
, default:{}
) –
Methods:
-
__delitem__
–Delete a member with its name or path.
-
__getitem__
–Get a member with its name or path.
-
__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_exported
–Tell if this object/alias is implicitely exported by its parent.
-
is_kind
–Tell if this object is of the given kind.
-
is_public
–Whether this object is considered public.
-
member_is_exported
–Whether a member of this object is "exported".
-
resolve
–Resolve a name within this object's and parents' scope.
-
set_member
–Set a member with its name or path.
Attributes:
-
aliases
(dict[str, Alias]
) –The aliases pointing to this object.
-
all_members
(dict[str, Object | Alias]
) –All members (declared and inherited).
-
annotation
(str | Expr | None
) –The attribute type annotation.
-
attributes
(dict[str, Attribute]
) –The attribute members.
-
canonical_path
(str
) –The full dotted path of this object.
-
classes
(dict[str, Class]
) –The class members.
-
docstring
(Docstring | None
) –The object docstring.
-
endlineno
(int | None
) –The ending line number of the object.
-
exports
(set[str] | 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.
-
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
) –Whether this object (alias) is inherited.
-
inherited_members
(dict[str, Alias]
) –Members that are inherited from base classes.
-
is_alias
(bool
) –Whether this object is an alias.
-
is_attribute
(bool
) –Whether this object is an attribute.
-
is_class
(bool
) –Whether this object is a class.
-
is_collection
(bool
) –Whether this object is a (modules) collection.
-
is_explicitely_exported
(bool
) –Whether this object/alias is explicitely exported by its parent.
-
is_function
(bool
) –Whether this object is a function.
-
is_implicitely_exported
(bool
) –Whether this object/alias is implicitely exported by its parent.
-
is_init_module
(bool
) –Whether this object is an
__init__.py
module. -
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_subpackage
(bool
) –Whether this object is a subpackage.
-
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).
-
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.
-
package
(Module
) –The absolute top module (the package) of this object.
-
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.
-
runtime
(bool
) –Whether this object is available at runtime.
-
source
(str
) –The source code of this object.
-
value
(str | Expr | None
) –The attribute value.
all_members property
¤
All members (declared and inherited).
This method is part of the consumer API: do not use when producing Griffe trees!
annotation instance-attribute
¤
annotation: str | Expr | None = annotation
The attribute type annotation.
attributes property
¤
The attribute members.
This method is part of the consumer API: do not use when producing Griffe trees!
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).
classes property
¤
The class members.
This method is part of the consumer API: do not use when producing Griffe trees!
endlineno instance-attribute
¤
The ending line number of the object.
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.
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.
functions property
¤
The function members.
This method is part of the consumer API: do not use when producing Griffe trees!
has_docstrings property
¤
has_docstrings: bool
Whether this object or any of its members has a docstring (empty or not).
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 ...
).
inherited class-attribute
instance-attribute
¤
inherited: bool = False
Whether this object (alias) is inherited.
Objects can never be inherited, only aliases can.
inherited_members cached
property
¤
Members that are inherited from base classes.
This method is part of the consumer API: do not use when producing Griffe trees!
is_alias class-attribute
instance-attribute
¤
is_alias: bool = False
Whether this object is an alias.
is_collection class-attribute
instance-attribute
¤
is_collection: bool = False
Whether this object is a (modules) collection.
is_explicitely_exported property
¤
is_explicitely_exported: bool
Whether this object/alias is explicitely exported by its parent.
is_implicitely_exported property
¤
is_implicitely_exported: bool
Whether this object/alias is implicitely exported by its parent.
is_namespace_package property
¤
is_namespace_package: bool
Whether this object is a namespace package (top folder, no __init__.py
).
is_namespace_subpackage property
¤
is_namespace_subpackage: bool
Whether this object is a namespace subpackage.
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).
module property
¤
module: Module
The parent module of this object.
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!
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.
parent instance-attribute
¤
The parent of the object (none if top module).
path property
¤
path: str
The dotted path of this object.
On regular objects (not aliases), the path is the canonical path.
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.
Raises:
-
ValueError
–When the relative path could not be computed.
relative_package_filepath property
¤
relative_package_filepath: Path
The file path where this object was defined, relative to the top module path.
Raises:
-
ValueError
–When the relative path could not be computed.
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.
__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")]
__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")]
__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:
Examples:
>>> griffe_object["foo"] = foo
>>> griffe_object["path.to.bar"] = bar
>>> griffe_object[("path", "to", "qux")] = qux
as_dict ¤
as_json ¤
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"))
filter_members ¤
from_json classmethod
¤
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.
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")]
has_labels ¤
is_exported ¤
is_kind ¤
is_public ¤
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
public
attribute is set (boolean), return its value. - In strict mode, the object is public only if it is explicitely exported (listed in
__all__
). Strict mode should only be used for module members. - Otherwise, if name checks are enabled, the object is private if its name starts with an underscore.
- Otherwise, if the object is an alias, and is neither inherited from a base class, nor a member of a parent alias, it is not public.
- Otherwise, the object is public.
member_is_exported ¤
Whether a member of this object is "exported".
By exported, we mean that the object is included in the __all__
attribute of its parent module or class. When __all__
is not defined, we consider the member to be implicitely exported, unless it's a module and it was not imported, and unless it's not defined at runtime.
Parameters:
-
member
(Object | Alias
) –The member to verify.
-
explicitely
(bool
, default:True
) –Whether to only return True when
__all__
is defined.
Returns:
-
bool
–True or False.
resolve ¤
Resolve a name within this object's and parents' scope.
Parameters:
-
name
(str
) –The name to resolve.
Raises:
-
NameResolutionError
–When the name could not be resolved.
Returns:
-
str
–The resolved name.
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:
Examples:
>>> griffe_object.set_member("foo", foo)
>>> griffe_object.set_member("path.to.bar", bar)
>>> griffe_object.set_member(("path", "to", "qux", qux)
Class ¤
Class(
*args: Any,
bases: Sequence[Expr | str] | None = None,
decorators: list[Decorator] | None = None,
**kwargs: Any
)
flowchart TD
griffe.dataclasses.Class[Class]
griffe.dataclasses.Object[Object]
griffe.mixins.ObjectAliasMixin[ObjectAliasMixin]
griffe.mixins.GetMembersMixin[GetMembersMixin]
griffe.mixins.SetMembersMixin[SetMembersMixin]
griffe.mixins.DelMembersMixin[DelMembersMixin]
griffe.mixins.SerializationMixin[SerializationMixin]
griffe.dataclasses.Object --> griffe.dataclasses.Class
griffe.mixins.ObjectAliasMixin --> griffe.dataclasses.Object
griffe.mixins.GetMembersMixin --> griffe.mixins.ObjectAliasMixin
griffe.mixins.SetMembersMixin --> griffe.mixins.ObjectAliasMixin
griffe.mixins.DelMembersMixin --> griffe.mixins.ObjectAliasMixin
griffe.mixins.SerializationMixin --> griffe.mixins.ObjectAliasMixin
click griffe.dataclasses.Class href "" "griffe.dataclasses.Class"
click griffe.dataclasses.Object href "" "griffe.dataclasses.Object"
click griffe.mixins.ObjectAliasMixin href "" "griffe.mixins.ObjectAliasMixin"
click griffe.mixins.GetMembersMixin href "" "griffe.mixins.GetMembersMixin"
click griffe.mixins.SetMembersMixin href "" "griffe.mixins.SetMembersMixin"
click griffe.mixins.DelMembersMixin href "" "griffe.mixins.DelMembersMixin"
click griffe.mixins.SerializationMixin href "" "griffe.mixins.SerializationMixin"
The class representing a Python class.
Parameters:
-
*args
(Any
, default:()
) – -
bases
(Sequence[Expr | str] | None
, default:None
) –The list of base classes, if any.
-
decorators
(list[Decorator] | None
, default:None
) –The class decorators, if any.
-
**kwargs
(Any
, default:{}
) –
Methods:
-
__delitem__
–Delete a member with its name or path.
-
__getitem__
–Get a member with its name or path.
-
__setitem__
–Set a member with its name or path.
-
as_dict
–Return this class' 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_exported
–Tell if this object/alias is implicitely exported by its parent.
-
is_kind
–Tell if this object is of the given kind.
-
is_public
–Whether this object is considered public.
-
member_is_exported
–Whether a member of this object is "exported".
-
mro
–Return a list of classes in order corresponding to Python's MRO.
-
resolve
–Resolve a name within this object's and parents' scope.
-
set_member
–Set a member with its name or path.
Attributes:
-
aliases
(dict[str, Alias]
) –The aliases pointing to this object.
-
all_members
(dict[str, Object | Alias]
) –All members (declared and inherited).
-
attributes
(dict[str, Attribute]
) –The attribute members.
-
bases
(list[Expr | str]
) –The class bases.
-
canonical_path
(str
) –The full dotted path of this object.
-
classes
(dict[str, Class]
) –The class members.
-
decorators
(list[Decorator]
) –The class decorators.
-
docstring
(Docstring | None
) –The object docstring.
-
endlineno
(int | None
) –The ending line number of the object.
-
exports
(set[str] | 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.
-
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
) –Whether this object (alias) is inherited.
-
inherited_members
(dict[str, Alias]
) –Members that are inherited from base classes.
-
is_alias
(bool
) –Whether this object is an alias.
-
is_attribute
(bool
) –Whether this object is an attribute.
-
is_class
(bool
) –Whether this object is a class.
-
is_collection
(bool
) –Whether this object is a (modules) collection.
-
is_explicitely_exported
(bool
) –Whether this object/alias is explicitely exported by its parent.
-
is_function
(bool
) –Whether this object is a function.
-
is_implicitely_exported
(bool
) –Whether this object/alias is implicitely exported by its parent.
-
is_init_module
(bool
) –Whether this object is an
__init__.py
module. -
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_subpackage
(bool
) –Whether this object is a subpackage.
-
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).
-
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
(dict[str, list[Function]]
) –The overloaded signatures declared in this class.
-
package
(Module
) –The absolute top module (the package) of this object.
-
parameters
(Parameters
) –The parameters of this class'
__init__
method, if any. -
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.
-
resolved_bases
(list[Object]
) –Resolved class bases.
-
runtime
(bool
) –Whether this object is available at runtime.
-
source
(str
) –The source code of this object.
all_members property
¤
All members (declared and inherited).
This method is part of the consumer API: do not use when producing Griffe trees!
attributes property
¤
The attribute members.
This method is part of the consumer API: do not use when producing Griffe trees!
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).
classes property
¤
The class members.
This method is part of the consumer API: do not use when producing Griffe trees!
decorators instance-attribute
¤
decorators: list[Decorator] = decorators or []
The class decorators.
endlineno instance-attribute
¤
The ending line number of the object.
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.
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.
functions property
¤
The function members.
This method is part of the consumer API: do not use when producing Griffe trees!
has_docstrings property
¤
has_docstrings: bool
Whether this object or any of its members has a docstring (empty or not).
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 ...
).
inherited class-attribute
instance-attribute
¤
inherited: bool = False
Whether this object (alias) is inherited.
Objects can never be inherited, only aliases can.
inherited_members cached
property
¤
Members that are inherited from base classes.
This method is part of the consumer API: do not use when producing Griffe trees!
is_alias class-attribute
instance-attribute
¤
is_alias: bool = False
Whether this object is an alias.
is_collection class-attribute
instance-attribute
¤
is_collection: bool = False
Whether this object is a (modules) collection.
is_explicitely_exported property
¤
is_explicitely_exported: bool
Whether this object/alias is explicitely exported by its parent.
is_implicitely_exported property
¤
is_implicitely_exported: bool
Whether this object/alias is implicitely exported by its parent.
is_namespace_package property
¤
is_namespace_package: bool
Whether this object is a namespace package (top folder, no __init__.py
).
is_namespace_subpackage property
¤
is_namespace_subpackage: bool
Whether this object is a namespace subpackage.
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).
module property
¤
module: Module
The parent module of this object.
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!
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.
overloads instance-attribute
¤
The overloaded signatures declared in this class.
parameters property
¤
parameters: Parameters
The parameters of this class' __init__
method, if any.
This property fetches inherited members, and therefore is part of the consumer API: do not use when producing Griffe trees!
parent instance-attribute
¤
The parent of the object (none if top module).
path property
¤
path: str
The dotted path of this object.
On regular objects (not aliases), the path is the canonical path.
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.
Raises:
-
ValueError
–When the relative path could not be computed.
relative_package_filepath property
¤
relative_package_filepath: Path
The file path where this object was defined, relative to the top module path.
Raises:
-
ValueError
–When the relative path could not be computed.
resolved_bases cached
property
¤
Resolved class bases.
This method is part of the consumer API: do not use when producing Griffe trees!
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.
__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")]
__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")]
__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:
Examples:
>>> griffe_object["foo"] = foo
>>> griffe_object["path.to.bar"] = bar
>>> griffe_object[("path", "to", "qux")] = qux
as_dict ¤
as_json ¤
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"))
filter_members ¤
from_json classmethod
¤
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.
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")]
has_labels ¤
is_exported ¤
is_kind ¤
is_public ¤
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
public
attribute is set (boolean), return its value. - In strict mode, the object is public only if it is explicitely exported (listed in
__all__
). Strict mode should only be used for module members. - Otherwise, if name checks are enabled, the object is private if its name starts with an underscore.
- Otherwise, if the object is an alias, and is neither inherited from a base class, nor a member of a parent alias, it is not public.
- Otherwise, the object is public.
member_is_exported ¤
Whether a member of this object is "exported".
By exported, we mean that the object is included in the __all__
attribute of its parent module or class. When __all__
is not defined, we consider the member to be implicitely exported, unless it's a module and it was not imported, and unless it's not defined at runtime.
Parameters:
-
member
(Object | Alias
) –The member to verify.
-
explicitely
(bool
, default:True
) –Whether to only return True when
__all__
is defined.
Returns:
-
bool
–True or False.
resolve ¤
Resolve a name within this object's and parents' scope.
Parameters:
-
name
(str
) –The name to resolve.
Raises:
-
NameResolutionError
–When the name could not be resolved.
Returns:
-
str
–The resolved name.
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:
Examples:
>>> griffe_object.set_member("foo", foo)
>>> griffe_object.set_member("path.to.bar", bar)
>>> griffe_object.set_member(("path", "to", "qux", qux)
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.
Methods:
-
as_dict
–Return this decorator's data as a dictionary.
Attributes:
Docstring ¤
Docstring(
value: str,
*,
lineno: int | None = None,
endlineno: int | None = None,
parent: Object | None = None,
parser: (
Literal["google", "numpy", "sphinx"] | Parser | None
) = None,
parser_options: dict[str, Any] | None = None
)
This class represents docstrings.
Parameters:
-
value
(str
) –The docstring value.
-
lineno
(int | None
, default:None
) –The starting line number.
-
endlineno
(int | None
, default:None
) –The ending line number.
-
parent
(Object | None
, default:None
) –The parent object on which this docstring is attached.
-
parser
(Literal['google', 'numpy', 'sphinx'] | Parser | None
, default:None
) –The docstring parser to use. By default, no parsing is done.
-
parser_options
(dict[str, Any] | None
, default:None
) –Additional docstring parsing options.
Methods:
-
as_dict
–Return this docstring's data as a dictionary.
-
parse
–Parse the docstring into structured data.
Attributes:
-
endlineno
(int | None
) –The ending line number of the docstring.
-
lineno
(int | None
) –The starting line number of the docstring.
-
lines
(list[str]
) –The lines of the docstring.
-
parent
(Object | None
) –The object this docstring is attached to.
-
parsed
(list[DocstringSection]
) –The docstring sections, parsed into structured data.
-
parser
(Literal['google', 'numpy', 'sphinx'] | Parser | None
) –The selected docstring parser.
-
parser_options
(dict[str, Any]
) –The configured parsing options.
-
value
(str
) –The original value of the docstring, cleaned by
inspect.cleandoc
.
endlineno instance-attribute
¤
The ending line number of the docstring.
parent instance-attribute
¤
The object this docstring is attached to.
parsed cached
property
¤
parsed: list[DocstringSection]
The docstring sections, parsed into structured data.
parser instance-attribute
¤
The selected docstring parser.
parser_options instance-attribute
¤
parser_options: dict[str, Any] = parser_options or {}
The configured parsing options.
value instance-attribute
¤
The original value of the docstring, cleaned by inspect.cleandoc
.
as_dict ¤
as_dict(
*,
full: bool = False,
docstring_parser: Parser | None = None,
**kwargs: Any
) -> dict[str, Any]
Return this docstring's data as a dictionary.
Parameters:
-
full
(bool
, default:False
) –Whether to return full info, or just base info.
-
docstring_parser
(Parser | None
, default:None
) –Deprecated. The docstring parser to parse the docstring with. By default, no parsing is done.
-
**kwargs
(Any
, default:{}
) –Additional serialization options.
Returns:
parse ¤
parse(
parser: (
Literal["google", "numpy", "sphinx"] | Parser | None
) = None,
**options: Any
) -> list[DocstringSection]
Parse the docstring into structured data.
Parameters:
-
parser
(Literal['google', 'numpy', 'sphinx'] | Parser | None
, default:None
) –The docstring parser to use. In order: use the given parser, or the self parser, or no parser (return a single text section).
-
**options
(Any
, default:{}
) –Additional docstring parsing options.
Returns:
-
list[DocstringSection]
–The parsed docstring as a list of sections.
Function ¤
Function(
*args: Any,
parameters: Parameters | None = None,
returns: str | Expr | None = None,
decorators: list[Decorator] | None = None,
**kwargs: Any
)
flowchart TD
griffe.dataclasses.Function[Function]
griffe.dataclasses.Object[Object]
griffe.mixins.ObjectAliasMixin[ObjectAliasMixin]
griffe.mixins.GetMembersMixin[GetMembersMixin]
griffe.mixins.SetMembersMixin[SetMembersMixin]
griffe.mixins.DelMembersMixin[DelMembersMixin]
griffe.mixins.SerializationMixin[SerializationMixin]
griffe.dataclasses.Object --> griffe.dataclasses.Function
griffe.mixins.ObjectAliasMixin --> griffe.dataclasses.Object
griffe.mixins.GetMembersMixin --> griffe.mixins.ObjectAliasMixin
griffe.mixins.SetMembersMixin --> griffe.mixins.ObjectAliasMixin
griffe.mixins.DelMembersMixin --> griffe.mixins.ObjectAliasMixin
griffe.mixins.SerializationMixin --> griffe.mixins.ObjectAliasMixin
click griffe.dataclasses.Function href "" "griffe.dataclasses.Function"
click griffe.dataclasses.Object href "" "griffe.dataclasses.Object"
click griffe.mixins.ObjectAliasMixin href "" "griffe.mixins.ObjectAliasMixin"
click griffe.mixins.GetMembersMixin href "" "griffe.mixins.GetMembersMixin"
click griffe.mixins.SetMembersMixin href "" "griffe.mixins.SetMembersMixin"
click griffe.mixins.DelMembersMixin href "" "griffe.mixins.DelMembersMixin"
click griffe.mixins.SerializationMixin href "" "griffe.mixins.SerializationMixin"
The class representing a Python function.
Parameters:
-
*args
(Any
, default:()
) – -
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:{}
) –
Methods:
-
__delitem__
–Delete a member with its name or path.
-
__getitem__
–Get a member with its name or path.
-
__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_exported
–Tell if this object/alias is implicitely exported by its parent.
-
is_kind
–Tell if this object is of the given kind.
-
is_public
–Whether this object is considered public.
-
member_is_exported
–Whether a member of this object is "exported".
-
resolve
–Resolve a name within this object's and parents' scope.
-
set_member
–Set a member with its name or path.
Attributes:
-
aliases
(dict[str, Alias]
) –The aliases pointing to this object.
-
all_members
(dict[str, Object | Alias]
) –All members (declared and inherited).
-
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.
-
deleter
(Function | None
) –The deleter linked to this function (property).
-
docstring
(Docstring | None
) –The object docstring.
-
endlineno
(int | None
) –The ending line number of the object.
-
exports
(set[str] | 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.
-
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
) –Whether this object (alias) is inherited.
-
inherited_members
(dict[str, Alias]
) –Members that are inherited from base classes.
-
is_alias
(bool
) –Whether this object is an alias.
-
is_attribute
(bool
) –Whether this object is an attribute.
-
is_class
(bool
) –Whether this object is a class.
-
is_collection
(bool
) –Whether this object is a (modules) collection.
-
is_explicitely_exported
(bool
) –Whether this object/alias is explicitely exported by its parent.
-
is_function
(bool
) –Whether this object is a function.
-
is_implicitely_exported
(bool
) –Whether this object/alias is implicitely exported by its parent.
-
is_init_module
(bool
) –Whether this object is an
__init__.py
module. -
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_subpackage
(bool
) –Whether this object is a subpackage.
-
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).
-
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.
-
setter
(Function | None
) –The setter linked to this function (property).
-
source
(str
) –The source code of this object.
all_members property
¤
All members (declared and inherited).
This method is part of the consumer API: do not use when producing Griffe trees!
attributes property
¤
The attribute members.
This method is part of the consumer API: do not use when producing Griffe trees!
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).
classes property
¤
The class members.
This method is part of the consumer API: do not use when producing Griffe trees!
decorators instance-attribute
¤
decorators: list[Decorator] = decorators or []
The function decorators.
deleter instance-attribute
¤
deleter: Function | None = None
The deleter linked to this function (property).
endlineno instance-attribute
¤
The ending line number of the object.
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.
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.
functions property
¤
The function members.
This method is part of the consumer API: do not use when producing Griffe trees!
has_docstrings property
¤
has_docstrings: bool
Whether this object or any of its members has a docstring (empty or not).
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 ...
).
inherited class-attribute
instance-attribute
¤
inherited: bool = False
Whether this object (alias) is inherited.
Objects can never be inherited, only aliases can.
inherited_members cached
property
¤
Members that are inherited from base classes.
This method is part of the consumer API: do not use when producing Griffe trees!
is_alias class-attribute
instance-attribute
¤
is_alias: bool = False
Whether this object is an alias.
is_collection class-attribute
instance-attribute
¤
is_collection: bool = False
Whether this object is a (modules) collection.
is_explicitely_exported property
¤
is_explicitely_exported: bool
Whether this object/alias is explicitely exported by its parent.
is_implicitely_exported property
¤
is_implicitely_exported: bool
Whether this object/alias is implicitely exported by its parent.
is_namespace_package property
¤
is_namespace_package: bool
Whether this object is a namespace package (top folder, no __init__.py
).
is_namespace_subpackage property
¤
is_namespace_subpackage: bool
Whether this object is a namespace subpackage.
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).
module property
¤
module: Module
The parent module of this object.
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!
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.
overloads instance-attribute
¤
The overloaded signatures of this function.
parameters instance-attribute
¤
parameters: Parameters = parameters or Parameters()
The function parameters.
parent instance-attribute
¤
The parent of the object (none if top module).
path property
¤
path: str
The dotted path of this object.
On regular objects (not aliases), the path is the canonical path.
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.
Raises:
-
ValueError
–When the relative path could not be computed.
relative_package_filepath property
¤
relative_package_filepath: Path
The file path where this object was defined, relative to the top module path.
Raises:
-
ValueError
–When the relative path could not be computed.
returns instance-attribute
¤
The function return type annotation.
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.
setter instance-attribute
¤
setter: Function | None = None
The setter linked to this function (property).
__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")]
__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")]
__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:
Examples:
>>> griffe_object["foo"] = foo
>>> griffe_object["path.to.bar"] = bar
>>> griffe_object[("path", "to", "qux")] = qux
as_dict ¤
as_json ¤
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"))
filter_members ¤
from_json classmethod
¤
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.
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")]
has_labels ¤
is_exported ¤
is_kind ¤
is_public ¤
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
public
attribute is set (boolean), return its value. - In strict mode, the object is public only if it is explicitely exported (listed in
__all__
). Strict mode should only be used for module members. - Otherwise, if name checks are enabled, the object is private if its name starts with an underscore.
- Otherwise, if the object is an alias, and is neither inherited from a base class, nor a member of a parent alias, it is not public.
- Otherwise, the object is public.
member_is_exported ¤
Whether a member of this object is "exported".
By exported, we mean that the object is included in the __all__
attribute of its parent module or class. When __all__
is not defined, we consider the member to be implicitely exported, unless it's a module and it was not imported, and unless it's not defined at runtime.
Parameters:
-
member
(Object | Alias
) –The member to verify.
-
explicitely
(bool
, default:True
) –Whether to only return True when
__all__
is defined.
Returns:
-
bool
–True or False.
resolve ¤
Resolve a name within this object's and parents' scope.
Parameters:
-
name
(str
) –The name to resolve.
Raises:
-
NameResolutionError
–When the name could not be resolved.
Returns:
-
str
–The resolved name.
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:
Examples:
>>> griffe_object.set_member("foo", foo)
>>> griffe_object.set_member("path.to.bar", bar)
>>> griffe_object.set_member(("path", "to", "qux", qux)
Kind ¤
flowchart TD
griffe.dataclasses.Kind[Kind]
click griffe.dataclasses.Kind href "" "griffe.dataclasses.Kind"
Enumeration of the different object kinds.
Attributes:
Module ¤
flowchart TD
griffe.dataclasses.Module[Module]
griffe.dataclasses.Object[Object]
griffe.mixins.ObjectAliasMixin[ObjectAliasMixin]
griffe.mixins.GetMembersMixin[GetMembersMixin]
griffe.mixins.SetMembersMixin[SetMembersMixin]
griffe.mixins.DelMembersMixin[DelMembersMixin]
griffe.mixins.SerializationMixin[SerializationMixin]
griffe.dataclasses.Object --> griffe.dataclasses.Module
griffe.mixins.ObjectAliasMixin --> griffe.dataclasses.Object
griffe.mixins.GetMembersMixin --> griffe.mixins.ObjectAliasMixin
griffe.mixins.SetMembersMixin --> griffe.mixins.ObjectAliasMixin
griffe.mixins.DelMembersMixin --> griffe.mixins.ObjectAliasMixin
griffe.mixins.SerializationMixin --> griffe.mixins.ObjectAliasMixin
click griffe.dataclasses.Module href "" "griffe.dataclasses.Module"
click griffe.dataclasses.Object href "" "griffe.dataclasses.Object"
click griffe.mixins.ObjectAliasMixin href "" "griffe.mixins.ObjectAliasMixin"
click griffe.mixins.GetMembersMixin href "" "griffe.mixins.GetMembersMixin"
click griffe.mixins.SetMembersMixin href "" "griffe.mixins.SetMembersMixin"
click griffe.mixins.DelMembersMixin href "" "griffe.mixins.DelMembersMixin"
click griffe.mixins.SerializationMixin href "" "griffe.mixins.SerializationMixin"
The class representing a Python module.
Parameters:
-
*args
(Any
, default:()
) – -
filepath
(Path | list[Path] | None
, default:None
) –The module file path (directory for namespace [sub]packages, none for builtin modules).
-
**kwargs
(Any
, default:{}
) –
Methods:
-
__delitem__
–Delete a member with its name or path.
-
__getitem__
–Get a member with its name or path.
-
__setitem__
–Set a member with its name or path.
-
as_dict
–Return this module'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_exported
–Tell if this object/alias is implicitely exported by its parent.
-
is_kind
–Tell if this object is of the given kind.
-
is_public
–Whether this object is considered public.
-
member_is_exported
–Whether a member of this object is "exported".
-
resolve
–Resolve a name within this object's and parents' scope.
-
set_member
–Set a member with its name or path.
Attributes:
-
aliases
(dict[str, Alias]
) –The aliases pointing to this object.
-
all_members
(dict[str, Object | Alias]
) –All members (declared and inherited).
-
attributes
(dict[str, Attribute]
) –The attribute members.
-
canonical_path
(str
) –The full dotted path of this object.
-
classes
(dict[str, Class]
) –The class members.
-
docstring
(Docstring | None
) –The object docstring.
-
endlineno
(int | None
) –The ending line number of the object.
-
exports
(set[str] | 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 of this module.
-
functions
(dict[str, Function]
) –The function members.
-
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.
-
imports_future_annotations
(bool
) –Whether this module import future annotations.
-
inherited
(bool
) –Whether this object (alias) is inherited.
-
inherited_members
(dict[str, Alias]
) –Members that are inherited from base classes.
-
is_alias
(bool
) –Whether this object is an alias.
-
is_attribute
(bool
) –Whether this object is an attribute.
-
is_class
(bool
) –Whether this object is a class.
-
is_collection
(bool
) –Whether this object is a (modules) collection.
-
is_explicitely_exported
(bool
) –Whether this object/alias is explicitely exported by its parent.
-
is_function
(bool
) –Whether this object is a function.
-
is_implicitely_exported
(bool
) –Whether this object/alias is implicitely exported by its parent.
-
is_init_module
(bool
) –Whether this module is an
__init__.py
module. -
is_module
(bool
) –Whether this object is a module.
-
is_namespace_package
(bool
) –Whether this module is a namespace package (top folder, no
__init__.py
). -
is_namespace_subpackage
(bool
) –Whether this module is a namespace subpackage.
-
is_package
(bool
) –Whether this module is a package (top module).
-
is_subpackage
(bool
) –Whether this module is a subpackage.
-
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).
-
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
(dict[str, list[Function]]
) –The overloaded signature declared in this module.
-
package
(Module
) –The absolute top module (the package) of this object.
-
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.
-
runtime
(bool
) –Whether this object is available at runtime.
-
source
(str
) –The source code of this object.
all_members property
¤
All members (declared and inherited).
This method is part of the consumer API: do not use when producing Griffe trees!
attributes property
¤
The attribute members.
This method is part of the consumer API: do not use when producing Griffe trees!
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).
classes property
¤
The class members.
This method is part of the consumer API: do not use when producing Griffe trees!
endlineno instance-attribute
¤
The ending line number of the object.
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.
extra instance-attribute
¤
Namespaced dictionaries storing extra metadata for this object, used by extensions.
filepath property
¤
functions property
¤
The function members.
This method is part of the consumer API: do not use when producing Griffe trees!
has_docstrings property
¤
has_docstrings: bool
Whether this object or any of its members has a docstring (empty or not).
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 ...
).
imports_future_annotations property
¤
imports_future_annotations: bool
Whether this module import future annotations.
inherited class-attribute
instance-attribute
¤
inherited: bool = False
Whether this object (alias) is inherited.
Objects can never be inherited, only aliases can.
inherited_members cached
property
¤
Members that are inherited from base classes.
This method is part of the consumer API: do not use when producing Griffe trees!
is_alias class-attribute
instance-attribute
¤
is_alias: bool = False
Whether this object is an alias.
is_collection class-attribute
instance-attribute
¤
is_collection: bool = False
Whether this object is a (modules) collection.
is_explicitely_exported property
¤
is_explicitely_exported: bool
Whether this object/alias is explicitely exported by its parent.
is_implicitely_exported property
¤
is_implicitely_exported: bool
Whether this object/alias is implicitely exported by its parent.
is_namespace_package property
¤
is_namespace_package: bool
Whether this module is a namespace package (top folder, no __init__.py
).
is_namespace_subpackage property
¤
is_namespace_subpackage: bool
Whether this module is a namespace subpackage.
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).
module property
¤
module: Module
The parent module of this object.
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!
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.
overloads instance-attribute
¤
The overloaded signature declared in this module.
parent instance-attribute
¤
The parent of the object (none if top module).
path property
¤
path: str
The dotted path of this object.
On regular objects (not aliases), the path is the canonical path.
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.
Raises:
-
ValueError
–When the relative path could not be computed.
relative_package_filepath property
¤
relative_package_filepath: Path
The file path where this object was defined, relative to the top module path.
Raises:
-
ValueError
–When the relative path could not be computed.
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.
__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")]
__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")]
__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:
Examples:
>>> griffe_object["foo"] = foo
>>> griffe_object["path.to.bar"] = bar
>>> griffe_object[("path", "to", "qux")] = qux
as_dict ¤
as_json ¤
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"))
filter_members ¤
from_json classmethod
¤
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.
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")]
has_labels ¤
is_exported ¤
is_kind ¤
is_public ¤
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
public
attribute is set (boolean), return its value. - In strict mode, the object is public only if it is explicitely exported (listed in
__all__
). Strict mode should only be used for module members. - Otherwise, if name checks are enabled, the object is private if its name starts with an underscore.
- Otherwise, if the object is an alias, and is neither inherited from a base class, nor a member of a parent alias, it is not public.
- Otherwise, the object is public.
member_is_exported ¤
Whether a member of this object is "exported".
By exported, we mean that the object is included in the __all__
attribute of its parent module or class. When __all__
is not defined, we consider the member to be implicitely exported, unless it's a module and it was not imported, and unless it's not defined at runtime.
Parameters:
-
member
(Object | Alias
) –The member to verify.
-
explicitely
(bool
, default:True
) –Whether to only return True when
__all__
is defined.
Returns:
-
bool
–True or False.
resolve ¤
Resolve a name within this object's and parents' scope.
Parameters:
-
name
(str
) –The name to resolve.
Raises:
-
NameResolutionError
–When the name could not be resolved.
Returns:
-
str
–The resolved name.
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:
Examples:
>>> griffe_object.set_member("foo", foo)
>>> griffe_object.set_member("path.to.bar", bar)
>>> griffe_object.set_member(("path", "to", "qux", qux)
Object ¤
Object(
name: str,
*,
lineno: int | None = None,
endlineno: int | None = None,
runtime: bool = True,
docstring: Docstring | None = None,
parent: Module | Class | None = None,
lines_collection: LinesCollection | None = None,
modules_collection: ModulesCollection | None = None
)
flowchart TD
griffe.dataclasses.Object[Object]
griffe.mixins.ObjectAliasMixin[ObjectAliasMixin]
griffe.mixins.GetMembersMixin[GetMembersMixin]
griffe.mixins.SetMembersMixin[SetMembersMixin]
griffe.mixins.DelMembersMixin[DelMembersMixin]
griffe.mixins.SerializationMixin[SerializationMixin]
griffe.mixins.ObjectAliasMixin --> griffe.dataclasses.Object
griffe.mixins.GetMembersMixin --> griffe.mixins.ObjectAliasMixin
griffe.mixins.SetMembersMixin --> griffe.mixins.ObjectAliasMixin
griffe.mixins.DelMembersMixin --> griffe.mixins.ObjectAliasMixin
griffe.mixins.SerializationMixin --> griffe.mixins.ObjectAliasMixin
click griffe.dataclasses.Object href "" "griffe.dataclasses.Object"
click griffe.mixins.ObjectAliasMixin href "" "griffe.mixins.ObjectAliasMixin"
click griffe.mixins.GetMembersMixin href "" "griffe.mixins.GetMembersMixin"
click griffe.mixins.SetMembersMixin href "" "griffe.mixins.SetMembersMixin"
click griffe.mixins.DelMembersMixin href "" "griffe.mixins.DelMembersMixin"
click griffe.mixins.SerializationMixin href "" "griffe.mixins.SerializationMixin"
An abstract class representing a Python object.
Parameters:
-
name
(str
) –The object name, as declared in the code.
-
lineno
(int | None
, default:None
) –The object starting line, or None for modules. Lines start at 1.
-
endlineno
(int | None
, default:None
) –The object ending line (inclusive), or None for modules.
-
runtime
(bool
, default:True
) –Whether this object is present at runtime or not.
-
docstring
(Docstring | None
, default:None
) –The object docstring.
-
parent
(Module | Class | None
, default:None
) –The object parent.
-
lines_collection
(LinesCollection | None
, default:None
) –A collection of source code lines.
-
modules_collection
(ModulesCollection | None
, default:None
) –A collection of modules.
Methods:
-
__delitem__
–Delete a member with its name or path.
-
__getitem__
–Get a member with its name or path.
-
__setitem__
–Set a member with its name or path.
-
as_dict
–Return this object'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_exported
–Tell if this object/alias is implicitely exported by its parent.
-
is_kind
–Tell if this object is of the given kind.
-
is_public
–Whether this object is considered public.
-
member_is_exported
–Whether a member of this object is "exported".
-
resolve
–Resolve a name within this object's and parents' scope.
-
set_member
–Set a member with its name or path.
Attributes:
-
aliases
(dict[str, Alias]
) –The aliases pointing to this object.
-
all_members
(dict[str, Object | Alias]
) –All members (declared and inherited).
-
attributes
(dict[str, Attribute]
) –The attribute members.
-
canonical_path
(str
) –The full dotted path of this object.
-
classes
(dict[str, Class]
) –The class members.
-
docstring
(Docstring | None
) –The object docstring.
-
endlineno
(int | None
) –The ending line number of the object.
-
exports
(set[str] | 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.
-
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
) –Whether this object (alias) is inherited.
-
inherited_members
(dict[str, Alias]
) –Members that are inherited from base classes.
-
is_alias
(bool
) –Whether this object is an alias.
-
is_attribute
(bool
) –Whether this object is an attribute.
-
is_class
(bool
) –Whether this object is a class.
-
is_collection
(bool
) –Whether this object is a (modules) collection.
-
is_explicitely_exported
(bool
) –Whether this object/alias is explicitely exported by its parent.
-
is_function
(bool
) –Whether this object is a function.
-
is_implicitely_exported
(bool
) –Whether this object/alias is implicitely exported by its parent.
-
is_init_module
(bool
) –Whether this object is an
__init__.py
module. -
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_subpackage
(bool
) –Whether this object is a subpackage.
-
kind
(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).
-
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.
-
package
(Module
) –The absolute top module (the package) of this object.
-
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.
-
runtime
(bool
) –Whether this object is available at runtime.
-
source
(str
) –The source code of this object.
all_members property
¤
All members (declared and inherited).
This method is part of the consumer API: do not use when producing Griffe trees!
attributes property
¤
The attribute members.
This method is part of the consumer API: do not use when producing Griffe trees!
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).
classes property
¤
The class members.
This method is part of the consumer API: do not use when producing Griffe trees!
endlineno instance-attribute
¤
The ending line number of the object.
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.
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.
functions property
¤
The function members.
This method is part of the consumer API: do not use when producing Griffe trees!
has_docstrings property
¤
has_docstrings: bool
Whether this object or any of its members has a docstring (empty or not).
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 ...
).
inherited class-attribute
instance-attribute
¤
inherited: bool = False
Whether this object (alias) is inherited.
Objects can never be inherited, only aliases can.
inherited_members cached
property
¤
Members that are inherited from base classes.
This method is part of the consumer API: do not use when producing Griffe trees!
is_alias class-attribute
instance-attribute
¤
is_alias: bool = False
Whether this object is an alias.
is_collection class-attribute
instance-attribute
¤
is_collection: bool = False
Whether this object is a (modules) collection.
is_explicitely_exported property
¤
is_explicitely_exported: bool
Whether this object/alias is explicitely exported by its parent.
is_implicitely_exported property
¤
is_implicitely_exported: bool
Whether this object/alias is implicitely exported by its parent.
is_namespace_package property
¤
is_namespace_package: bool
Whether this object is a namespace package (top folder, no __init__.py
).
is_namespace_subpackage property
¤
is_namespace_subpackage: bool
Whether this object is a namespace subpackage.
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).
module property
¤
module: Module
The parent module of this object.
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!
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.
parent instance-attribute
¤
The parent of the object (none if top module).
path property
¤
path: str
The dotted path of this object.
On regular objects (not aliases), the path is the canonical path.
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.
Raises:
-
ValueError
–When the relative path could not be computed.
relative_package_filepath property
¤
relative_package_filepath: Path
The file path where this object was defined, relative to the top module path.
Raises:
-
ValueError
–When the relative path could not be computed.
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.
__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")]
__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")]
__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:
Examples:
>>> griffe_object["foo"] = foo
>>> griffe_object["path.to.bar"] = bar
>>> griffe_object[("path", "to", "qux")] = qux
as_dict ¤
as_json ¤
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"))
filter_members ¤
from_json classmethod
¤
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.
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")]
has_labels ¤
is_exported ¤
is_kind ¤
is_public ¤
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
public
attribute is set (boolean), return its value. - In strict mode, the object is public only if it is explicitely exported (listed in
__all__
). Strict mode should only be used for module members. - Otherwise, if name checks are enabled, the object is private if its name starts with an underscore.
- Otherwise, if the object is an alias, and is neither inherited from a base class, nor a member of a parent alias, it is not public.
- Otherwise, the object is public.
member_is_exported ¤
Whether a member of this object is "exported".
By exported, we mean that the object is included in the __all__
attribute of its parent module or class. When __all__
is not defined, we consider the member to be implicitely exported, unless it's a module and it was not imported, and unless it's not defined at runtime.
Parameters:
-
member
(Object | Alias
) –The member to verify.
-
explicitely
(bool
, default:True
) –Whether to only return True when
__all__
is defined.
Returns:
-
bool
–True or False.
resolve ¤
Resolve a name within this object's and parents' scope.
Parameters:
-
name
(str
) –The name to resolve.
Raises:
-
NameResolutionError
–When the name could not be resolved.
Returns:
-
str
–The resolved name.
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:
Examples:
>>> griffe_object.set_member("foo", foo)
>>> griffe_object.set_member("path.to.bar", bar)
>>> griffe_object.set_member(("path", "to", "qux", qux)
Parameter ¤
Parameter(
name: str,
*,
annotation: str | Expr | None = None,
kind: ParameterKind | None = None,
default: str | Expr | None = None
)
This class represent a function parameter.
Parameters:
-
name
(str
) –The parameter name.
-
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.
Methods:
-
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.
-
kind
(ParameterKind | None
) –The parameter kind.
-
name
(str
) –The parameter name.
-
required
(bool
) –Whether this parameter is required.
annotation instance-attribute
¤
annotation: str | Expr | None = annotation
The parameter type annotation.
ParameterKind ¤
flowchart TD
griffe.dataclasses.ParameterKind[ParameterKind]
click griffe.dataclasses.ParameterKind href "" "griffe.dataclasses.ParameterKind"
Enumeration of the different parameter kinds.
Attributes:
-
keyword_only
(str
) –Keyword-only parameter.
-
positional_only
(str
) –Positional-only parameter.
-
positional_or_keyword
(str
) –Positional or keyword parameter.
-
var_keyword
(str
) –Variadic keyword parameter.
-
var_positional
(str
) –Variadic positional parameter.
keyword_only class-attribute
instance-attribute
¤
keyword_only: str = 'keyword-only'
Keyword-only parameter.
positional_only class-attribute
instance-attribute
¤
positional_only: str = 'positional-only'
Positional-only parameter.
positional_or_keyword class-attribute
instance-attribute
¤
positional_or_keyword: str = 'positional or keyword'
Positional or keyword parameter.
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
Parameters:
-
*parameters
(Parameter
, default:()
) –The initial parameters to add to the container.
Methods:
-
add
–Add a parameter to the container.
add ¤
add(parameter: Parameter) -> None
Add a parameter to the container.
Parameters:
-
parameter
(Parameter
) –The function parameter to add.
Raises:
-
ValueError
–When a parameter with the same name is already present.