Skip to content

Commit

Permalink
refactor: Renamed dataclasses internal modules to models
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Jul 14, 2024
1 parent cbce6a5 commit 5555de6
Show file tree
Hide file tree
Showing 45 changed files with 138 additions and 138 deletions.
24 changes: 12 additions & 12 deletions docs/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ both the visitor and inspector agents will trigger events.
These events can be hooked on by extensions to alter or enhance
Griffe's behavior. Some hooks will be passed just the current
node being visited, others will be passed both the node
and an instance of an [Object][griffe.dataclasses.Object] subclass,
such as a [Module][griffe.dataclasses.Module],
a [Class][griffe.dataclasses.Class],
a [Function][griffe.dataclasses.Function],
or an [Attribute][griffe.dataclasses.Attribute].
and an instance of an [Object][griffe.models.Object] subclass,
such as a [Module][griffe.models.Module],
a [Class][griffe.models.Class],
a [Function][griffe.models.Function],
or an [Attribute][griffe.models.Attribute].
Extensions will therefore be able to modify these instances.

The following flow chart shows an example of an AST visit.
Expand Down Expand Up @@ -180,11 +180,11 @@ contains a single class, which itself contains a single method:

- the agent (visitor or inspector) will walk through the tree
by starting with the module node
- it will instantiate a [Module][griffe.dataclasses.Module],
- it will instantiate a [Module][griffe.models.Module],
then walk through its members, continuing with the class node
- it will instantiate a [Class][griffe.dataclasses.Class],
- it will instantiate a [Class][griffe.models.Class],
then walk through its members, continuing with the function node
- it will instantiate a [Function][griffe.dataclasses.Function]
- it will instantiate a [Function][griffe.models.Function]
- then it will go back up and finish walking since there are
no more nodes to walk through

Expand Down Expand Up @@ -296,10 +296,10 @@ The "on node" events are triggered when the agent (visitor or inspector)
starts handling a node in the tree (AST or object tree).

The "on instance" events are triggered when the agent
just created an instance of [Module][griffe.dataclasses.Module],
[Class][griffe.dataclasses.Class],
[Function][griffe.dataclasses.Function],
or [Attribute][griffe.dataclasses.Attribute],
just created an instance of [Module][griffe.models.Module],
[Class][griffe.models.Class],
[Function][griffe.models.Function],
or [Attribute][griffe.models.Attribute],
and added it as a member of its parent.

The "on members" events are triggered when the agent
Expand Down
38 changes: 19 additions & 19 deletions docs/loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@ mkdocs = loader.load("mkdocs", submodules=False)
## Navigating into the loaded objects

Both the `load` function and the `GriffeLoader.load` method
return an [`Object`][griffe.dataclasses.Object] instance.
return an [`Object`][griffe.models.Object] instance.
There are several ways to access members of an object:

- through its `members` attribute, which is a dictionary,
with the usual `keys()`, `values()` and `items()` methods.
- thanks to its `__getitem__` method. For example `griffe["dataclasses"]`
returns the `Module` instance representing Griffe's `dataclasses` module.
Since this module also has members, you can chain calls: `griffe["dataclasses"]["Module"]`.
Conveniently, you can chain the names with dots in a single call: `griffe["dataclasses.Module"]`.
You can even pass a tuple instead of a string: `griffe[("dataclasses", "Module")]`.
- through the [`modules`][griffe.dataclasses.Object.modules],
[`classes`][griffe.dataclasses.Object.classes],
[`functions`][griffe.dataclasses.Object.functions] and
[`attributes`][griffe.dataclasses.Object.attributes] properties,
- thanks to its `__getitem__` method. For example `griffe["models"]`
returns the `Module` instance representing Griffe's `models` module.
Since this module also has members, you can chain calls: `griffe["models"]["Module"]`.
Conveniently, you can chain the names with dots in a single call: `griffe["models.Module"]`.
You can even pass a tuple instead of a string: `griffe[("models", "Module")]`.
- through the [`modules`][griffe.models.Object.modules],
[`classes`][griffe.models.Object.classes],
[`functions`][griffe.models.Object.functions] and
[`attributes`][griffe.models.Object.attributes] properties,
which take care of filtering members based on their kind, and return dictionaries.

Most of the time, you will only use classes from the [`griffe.dataclasses`][griffe.dataclasses]
and [`griffe.docstrings.dataclasses`][griffe.docstrings.dataclasses] modules.
Most of the time, you will only use classes from the [`griffe.models`][griffe.models]
and [`griffe.docstrings.models`][griffe.docstrings.models] modules.


## Class inheritance
Expand All @@ -64,7 +64,7 @@ from using inheritance support in Griffe.
Griffe supports class inheritance, both when visiting and inspecting modules.

To access members of a class that are inherited from base classes,
use [`Object.inherited_members`][griffe.dataclasses.Object.inherited_members].
use [`Object.inherited_members`][griffe.models.Object.inherited_members].
If this is the first time you access inherited members, the base classes
of the given class will be resolved and cached, then the MRO (Method Resolution Order)
will be computed for these bases classes, and a dictionary of inherited members
Expand Down Expand Up @@ -94,15 +94,15 @@ If a base class cannot be resolved during computation
of inherited members, Griffe logs a DEBUG message.

If you want to access all members at once (both declared and inherited),
use [`Object.all_members`][griffe.dataclasses.Object.all_members].
use [`Object.all_members`][griffe.models.Object.all_members].

If you want to access only declared members,
use [`Object.members`][griffe.dataclasses.Object].
use [`Object.members`][griffe.models.Object].

Accessing [`Object.attributes`][griffe.dataclasses.Object.attributes],
[`Object.functions`][griffe.dataclasses.Object.functions],
[`Object.classes`][griffe.dataclasses.Object.classes] or
[`Object.modules`][griffe.dataclasses.Object.modules]
Accessing [`Object.attributes`][griffe.models.Object.attributes],
[`Object.functions`][griffe.models.Object.functions],
[`Object.classes`][griffe.models.Object.classes] or
[`Object.modules`][griffe.models.Object.modules]
will trigger inheritance computation, so make sure to only call it
once everything is loaded by Griffe. Don't access inherited members
in extensions, while visiting or inspecting a module.
Expand Down
6 changes: 3 additions & 3 deletions docs/parsing_docstrings.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

You can use Griffe to parse arbitrary docstrings.
You don't have to load anything through the Griffe loader.
You just need to import the [`Docstring`][griffe.dataclasses.Docstring] class.
You just need to import the [`Docstring`][griffe.models.Docstring] class.
Then you can build a `Docstring` instance and call its `parse` method,
choosing the parsing-style to use:

```python
from griffe.dataclasses import Docstring
from griffe.models import Docstring

text = "Hello I'm a docstring!"
docstring = Docstring(text, lineno=1)
Expand All @@ -19,7 +19,7 @@ annotations from the object from which the docstring originates,
you can manually create the parent objects and link them to the docstring:

```python
from griffe.dataclasses import Docstring, Function, Parameters, Parameter, ParameterKind
from griffe.models import Docstring, Function, Parameters, Parameter, ParameterKind

function = Function(
"func",
Expand Down
Loading

0 comments on commit 5555de6

Please sign in to comment.