mixins ¤
This module contains some mixins classes about accessing and setting members.
Classes:
-
DelMembersMixin
–Mixin class to share methods for deleting members.
-
GetMembersMixin
–Mixin class to share methods for accessing members.
-
ObjectAliasMixin
–A mixin for methods that appear both in objects and aliases, unchanged.
-
SerializationMixin
–A mixin that adds de/serialization conveniences.
-
SetMembersMixin
–Mixin class to share methods for setting members.
DelMembersMixin ¤
Mixin class to share methods for deleting members.
Methods:
-
__delitem__
–Delete a member with its name or path.
-
del_member
–Delete a member with its name or path.
__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")]
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"))
GetMembersMixin ¤
Mixin class to share methods for accessing members.
Methods:
-
__getitem__
–Get a member with its name or path.
-
get_member
–Get a member with its name or path.
__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")]
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")]
ObjectAliasMixin ¤
flowchart TD
griffe.mixins.ObjectAliasMixin[ObjectAliasMixin]
griffe.mixins.GetMembersMixin[GetMembersMixin]
griffe.mixins.SetMembersMixin[SetMembersMixin]
griffe.mixins.DelMembersMixin[DelMembersMixin]
griffe.mixins.SerializationMixin[SerializationMixin]
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.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"
A mixin for methods that appear both in objects and aliases, unchanged.
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_json
–Return this object's data as a JSON string.
-
del_member
–Delete a member with its name or path.
-
from_json
–Create an instance of this class from a JSON string.
-
get_member
–Get a member with its name or path.
-
is_exported
–Tell if this object/alias is implicitely exported by its parent.
-
is_public
–Whether this object is considered public.
-
set_member
–Set a member with its name or path.
Attributes:
-
all_members
(dict[str, Object | Alias]
) –All members (declared and inherited).
-
attributes
(dict[str, Attribute]
) –The attribute members.
-
classes
(dict[str, Class]
) –The class members.
-
functions
(dict[str, Function]
) –The function members.
-
is_explicitely_exported
(bool
) –Whether this object/alias is explicitely exported by its parent.
-
is_implicitely_exported
(bool
) –Whether this object/alias is implicitely exported by its parent.
-
modules
(dict[str, Module]
) –The module members.
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!
classes property
¤
The class members.
This method is part of the consumer API: do not use when producing Griffe trees!
functions property
¤
The function members.
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.
modules property
¤
The module members.
This method is part of the consumer API: do not use when producing Griffe trees!
__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_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"))
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")]
is_exported ¤
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.
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)
SerializationMixin ¤
A mixin that adds de/serialization conveniences.
Methods:
-
as_json
–Return this object's data as a JSON string.
-
from_json
–Create an instance of this class from a JSON string.
as_json ¤
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.
SetMembersMixin ¤
Mixin class to share methods for setting members.
Methods:
-
__setitem__
–Set a member with its name or path.
-
set_member
–Set a member with its name or path.
__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
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)