Skip to content

mixins ¤

This module contains some mixins classes about accessing and setting members.

Classes:

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__ ¤

__delitem__(key: str | Sequence[str]) -> None

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 ¤

del_member(key: str | Sequence[str]) -> None

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__ ¤

__getitem__(key: str | Sequence[str]) -> Any

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_member(key: str | Sequence[str]) -> Any

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 property ¤

all_members: dict[str, Object | Alias]

All members (declared and inherited).

This method is part of the consumer API: do not use when producing Griffe trees!

attributes property ¤

attributes: dict[str, Attribute]

The attribute members.

This method is part of the consumer API: do not use when producing Griffe trees!

classes property ¤

classes: dict[str, Class]

The class members.

This method is part of the consumer API: do not use when producing Griffe trees!

functions property ¤

functions: dict[str, Function]

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 ¤

modules: dict[str, Module]

The module members.

This method is part of the consumer API: do not use when producing Griffe trees!

__delitem__ ¤

__delitem__(key: str | Sequence[str]) -> None

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__ ¤

__getitem__(key: str | Sequence[str]) -> Any

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__ ¤

__setitem__(
    key: str | Sequence[str], value: Object | Alias
) -> None

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 ¤

as_json(*, full: bool = False, **kwargs: Any) -> str

Return this object's data as a JSON string.

Parameters:

  • full (bool, default: False ) –

    Whether to return full info, or just base info.

  • **kwargs (Any, default: {} ) –

    Additional serialization options passed to encoder.

Returns:

  • str

    A JSON string.

del_member ¤

del_member(key: str | Sequence[str]) -> None

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 ¤

from_json(json_string: str, **kwargs: Any) -> _ObjType

Create an instance of this class from a JSON string.

Parameters:

  • json_string (str) –

    JSON to decode into Object.

  • **kwargs (Any, default: {} ) –

    Additional options passed to decoder.

Returns:

  • _ObjType

    An Object instance.

Raises:

  • TypeError

    When the json_string does not represent and object of the class from which this classmethod has been called.

get_member ¤

get_member(key: str | Sequence[str]) -> Any

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_exported(*, explicitely: bool = True) -> bool

Tell if this object/alias is implicitely exported by its parent.

Parameters:

  • explicitely (bool, default: True ) –

    Whether to only return True when __all__ is defined.

Returns:

  • bool

    True or False.

is_public ¤

is_public(
    *, strict: bool = False, check_name: bool = True
) -> bool

Whether this object is considered public.

In modules, developers can mark objects as public thanks to the __all__ variable. In classes however, there is no convention or standard to do so.

Therefore, to decide whether an object is public, we follow this algorithm:

  • If the object's 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_member(
    key: str | Sequence[str], value: Object | Alias
) -> None

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 ¤

as_json(*, full: bool = False, **kwargs: Any) -> str

Return this object's data as a JSON string.

Parameters:

  • full (bool, default: False ) –

    Whether to return full info, or just base info.

  • **kwargs (Any, default: {} ) –

    Additional serialization options passed to encoder.

Returns:

  • str

    A JSON string.

from_json classmethod ¤

from_json(json_string: str, **kwargs: Any) -> _ObjType

Create an instance of this class from a JSON string.

Parameters:

  • json_string (str) –

    JSON to decode into Object.

  • **kwargs (Any, default: {} ) –

    Additional options passed to decoder.

Returns:

  • _ObjType

    An Object instance.

Raises:

  • TypeError

    When the json_string does not represent and object of the class from which this classmethod has been called.

SetMembersMixin ¤

Mixin class to share methods for setting members.

Methods:

__setitem__ ¤

__setitem__(
    key: str | Sequence[str], value: Object | Alias
) -> None

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_member(
    key: str | Sequence[str], value: Object | Alias
) -> None

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)