Skip to content

collections ¤

This module stores collections of data, useful during parsing.

Classes:

  • LinesCollection

    A simple dictionary containing the modules source code lines.

  • ModulesCollection

    A collection of modules, allowing easy access to members.

LinesCollection ¤

LinesCollection()

A simple dictionary containing the modules source code lines.

Methods:

  • items

    Return the collection items.

  • keys

    Return the collection keys.

  • values

    Return the collection values.

items ¤

items() -> ItemsView

Return the collection items.

Returns:

keys ¤

keys() -> KeysView

Return the collection keys.

Returns:

values ¤

values() -> ValuesView

Return the collection values.

Returns:

ModulesCollection ¤

ModulesCollection()

          flowchart TD
          griffe.collections.ModulesCollection[ModulesCollection]
          griffe.mixins.GetMembersMixin[GetMembersMixin]
          griffe.mixins.SetMembersMixin[SetMembersMixin]
          griffe.mixins.DelMembersMixin[DelMembersMixin]

                        griffe.mixins.GetMembersMixin --> griffe.collections.ModulesCollection
              
              griffe.mixins.SetMembersMixin --> griffe.collections.ModulesCollection
              
              griffe.mixins.DelMembersMixin --> griffe.collections.ModulesCollection
              


          click griffe.collections.ModulesCollection href "" "griffe.collections.ModulesCollection"
          click griffe.mixins.GetMembersMixin href "" "griffe.mixins.GetMembersMixin"
          click griffe.mixins.SetMembersMixin href "" "griffe.mixins.SetMembersMixin"
          click griffe.mixins.DelMembersMixin href "" "griffe.mixins.DelMembersMixin"
          

A collection of modules, allowing easy access to members.

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.

  • del_member

    Delete a member with its name or path.

  • get_member

    Get a member with its name or path.

  • set_member

    Set a member with its name or path.

Attributes:

all_members property ¤

all_members: dict[str, Module]

Members of the collection.

This property is overwritten to simply return self.members, as all_members does not make sense for a modules collection.

members instance-attribute ¤

members: dict[str, Module] = {}

Members (modules) of the collection.

__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

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"))

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")]

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)