Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mkdocstrings/python
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.16.6
Choose a base ref
...
head repository: mkdocstrings/python
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.16.7
Choose a head ref
  • 3 commits
  • 30 files changed
  • 1 contributor

Commits on Mar 19, 2025

  1. Copy the full SHA
    9f43ed9 View commit details

Commits on Mar 20, 2025

  1. refactor: Prepare public filtering method feature

    Issue-78: #78
    pawamoy committed Mar 20, 2025
    Copy the full SHA
    fde2019 View commit details
  2. chore: Prepare release 1.16.7

    pawamoy committed Mar 20, 2025
    Copy the full SHA
    148f245 View commit details
Showing with 3,485 additions and 20 deletions.
  1. +8 −0 CHANGELOG.md
  2. +4 −0 docs/insiders/changelog.md
  3. +3 −0 docs/insiders/goals.yml
  4. +15 −4 docs/usage/configuration/members.md
  5. +1 −1 mkdocs.yml
  6. +19 −4 src/mkdocstrings_handlers/python/_internal/config.py
  7. +7 −5 src/mkdocstrings_handlers/python/_internal/rendering.py
  8. +5 −5 src/mkdocstrings_handlers/python/templates/material/_base/children.html.jinja
  9. +30 −0 tests/snapshots/__init__.py
  10. +22 −0 tests/snapshots/external/135f57223e006849dcdd1463367127e4c5ee4aba5f12bde17ab3e494dbeed490.html
  11. +506 −0 tests/snapshots/external/16295fa51a2c3a60d1461a9a14093603333f836326a007d8eb061f78ab38a712.html
  12. +22 −0 tests/snapshots/external/2e866eca9a45f82cd1e16bb55bbc2a03bb19548457598bca83141cb375fb1aa3.html
  13. +506 −0 tests/snapshots/external/37232379c426474cc962db72ded419e39c3e416c30e367c8745f3be4e86557a4.html
  14. +57 −0 tests/snapshots/external/408244423577f9b2598b319118c5f4a0a495116b06ebb2877a0964d526ec18e0.html
  15. +22 −0 tests/snapshots/external/46daa7e60b98815685904dd397f0de19cf1a94397d2165418a4f9fec02c7b560.html
  16. +24 −0 tests/snapshots/external/51d73351dc5546cefc8087b8409ebb7841c879fb48c875ff4cba6fbadee64014.html
  17. +24 −0 tests/snapshots/external/6abf5ddd819b832a1593ece448c90e63e13faa4376cca76b4fddc4d52a47f8b0.html
  18. +353 −0 tests/snapshots/external/6af55596d9c42d2634baadf77df6060caba2bd9c2d634576378cc18131c0efba.html
  19. +353 −0 tests/snapshots/external/6c0b7207df0351e1d5232859a5c13b72533fb8c87e5dc0e971b185f8dfe38c84.html
  20. +318 −0 tests/snapshots/external/6d72c524b827a2e4fd84a17b2aecfffca0d05bfa3fc38815f89836607e5a6c92.html
  21. +318 −0 tests/snapshots/external/74e2496015e194b88a30c9d0a4d9309bf74c122d1d24aecaa4d9c9c392057d1a.html
  22. +55 −0 tests/snapshots/external/80399c502938940d34e928b35648146970dc524534fe2e7f7127ccb32e3067d0.html
  23. +22 −0 tests/snapshots/external/9dab67183389335dadba724875c80c49909904aa135e65c6c411c3a903d458da.html
  24. +318 −0 tests/snapshots/external/a255ee80bf7a569ab3aa55ea94af24ce6671dace3d6075df5d14a3ff428ceb8b.html
  25. +318 −0 tests/snapshots/external/b4e20d5cd52e746cc7473537a2318a9ad886c5d8d8654c8d4f85fe209b04d86b.html
  26. +55 −0 tests/snapshots/external/d56d3aeae22be9b2494a085b812f0a3a5fabdbef184198de0462a0b944393891.html
  27. +55 −0 tests/snapshots/external/e254ae60f9af14754001bc63b74a3c473f5198cf2a58f4d30ad6d5a4c196e67c.html
  28. +22 −0 tests/snapshots/external/ed5d07bcdbaa3f295c0cb1544d54b196728ed6c70f4d6c902991baca6f16193c.html
  29. +22 −0 tests/snapshots/external/f48d651b3f1a2ce91910e05f4c3f7a7ec95e7d0e88d4503f101610d74029ce23.html
  30. +1 −1 tests/test_end_to_end.py
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -5,6 +5,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

<!-- insertion marker -->
## [1.16.7](https://github.com/mkdocstrings/python/releases/tag/1.16.7) - 2025-03-20

<small>[Compare with 1.16.6](https://github.com/mkdocstrings/python/compare/1.16.6...1.16.7)</small>

### Code Refactoring

- Prepare `public` filtering method feature ([fde2019](https://github.com/mkdocstrings/python/commit/fde20191cab20f39d9e5e729a95cdfa3390b8f1f) by Timothée Mazzucotelli). [Issue-78](https://github.com/mkdocstrings/python/issues/78)

## [1.16.6](https://github.com/mkdocstrings/python/releases/tag/1.16.6) - 2025-03-18

<small>[Compare with 1.16.5](https://github.com/mkdocstrings/python/compare/1.16.5...1.16.6)</small>
4 changes: 4 additions & 0 deletions docs/insiders/changelog.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,10 @@

## mkdocstrings-python Insiders

### 1.11.0 <small>March 20, 2025</small> { id="1.11.0" }

- [Filtering method: `public`][option-filters-public]

### 1.10.0 <small>March 10, 2025</small> { id="1.10.0" }

- [Backlinks][backlinks]
3 changes: 3 additions & 0 deletions docs/insiders/goals.yml
Original file line number Diff line number Diff line change
@@ -45,3 +45,6 @@ goals:
- name: Backlinks
ref: /usage/configuration/general/#backlinks
since: 2025/03/10
- name: "Filtering method: `public`"
ref: /usage/configuration/members/#option-filters-public
since: 2025/03/20
19 changes: 15 additions & 4 deletions docs/usage/configuration/members.md
Original file line number Diff line number Diff line change
@@ -335,10 +335,21 @@ def function_c():
[](){#option-filters}
## `filters`

- **:octicons-package-24: Type <code><autoref identifier="list" optional>list</autoref>[<autoref identifier="str" optional>str</autoref>] | None</code> :material-equal: `["!^_[^_]"]`{ title="default value" }**
- **:octicons-package-24: Type <code><autoref identifier="list" optional>list</autoref>[<autoref identifier="str" optional>str</autoref>] | <autoref identifier="typing.Literal" optional>Literal</autoref>["public"] | None</code> :material-equal: `["!^_[^_]"]`{ title="default value" }**
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->

A list of filters applied to filter objects based on their name.
A list of filters, or `"public"`.

**Filtering methods**

[](){#option-filters-public}

[:octicons-heart-fill-24:{ .pulse } Sponsors only](../../insiders/index.md){ .insiders } &mdash;
[:octicons-tag-24: Insiders 1.11.0](../../insiders/changelog.md#1.11.0)

The `public` filtering method will include only public objects: those added to the `__all__` attribute of modules, or not starting with a single underscore. Special methods and attributes ("dunder" methods/attributes, starting and ending with two underscores), like `__init__`, `__call__`, `__mult__`, etc., are always considered public.

**List of filters**

Filters are regular expressions. These regular expressions are evaluated by Python
and so must match the syntax supported by the [`re`][] module.
@@ -379,13 +390,13 @@ plugins:
python:
options:
filters:
- "!^_"
- "!^_[^_]"
```

```md title="or in docs/some_page.md (local configuration)"
::: package.module
options:
filters: []
filters: public
```

```python title="package/module.py"
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
@@ -160,7 +160,7 @@ plugins:
ignore_init_summary: true
docstring_section_style: list
extensions: [scripts/griffe_extensions.py]
filters: ["!^_"]
filters: public
heading_level: 1
inherited_members: true
line_length: 88
23 changes: 19 additions & 4 deletions src/mkdocstrings_handlers/python/_internal/config.py
Original file line number Diff line number Diff line change
@@ -432,14 +432,24 @@ class PythonInputOptions:
] = field(default_factory=list)

filters: Annotated[
list[str],
list[str] | Literal["public"],
_Field(
group="members",
description="""A list of filters applied to filter objects based on their name.
description="""A list of filters, or `"public"`.
**List of filters**
A filter starting with `!` will exclude matching objects instead of including them.
The `members` option takes precedence over `filters` (filters will still be applied recursively
to lower members in the hierarchy).
**Filtering methods**
[:octicons-heart-fill-24:{ .pulse } Sponsors only](../insiders/index.md){ .insiders } &mdash;
[:octicons-tag-24: Insiders 1.11.0](../insiders/changelog.md#1.11.0)
The `public` method will include only public objects:
those added to `__all__` or not starting with an underscore (except for special methods/attributes).
""",
),
] = field(default_factory=lambda: _DEFAULT_FILTERS.copy())
@@ -916,12 +926,12 @@ def from_data(cls, **data: Any) -> Self:
class PythonOptions(PythonInputOptions): # type: ignore[override,unused-ignore]
"""Final options passed as template context."""

filters: list[tuple[re.Pattern, bool]] = field( # type: ignore[assignment]
filters: list[tuple[re.Pattern, bool]] | Literal["public"] = field( # type: ignore[assignment]
default_factory=lambda: [
(re.compile(filtr.removeprefix("!")), filtr.startswith("!")) for filtr in _DEFAULT_FILTERS
],
)
"""A list of filters applied to filter objects based on their name."""
"""A list of filters, or `"public"`."""

summary: SummaryOption = field(default_factory=SummaryOption)
"""Whether to render summaries of modules, classes, functions (methods) and attributes."""
@@ -930,6 +940,11 @@ class PythonOptions(PythonInputOptions): # type: ignore[override,unused-ignore]
def coerce(cls, **data: Any) -> MutableMapping[str, Any]:
"""Create an instance from a dictionary."""
if "filters" in data:
# Non-insiders: transform back to default filters.
# Next: `if "filters" in data and not isinstance(data["filters"], str):`.
if data["filters"] == "public":
data["filters"] = _DEFAULT_FILTERS
# Filters are `None` or a sequence of strings (tests use tuples).
data["filters"] = [
(re.compile(filtr.removeprefix("!")), filtr.startswith("!")) for filtr in data["filters"] or ()
]
12 changes: 7 additions & 5 deletions src/mkdocstrings_handlers/python/_internal/rendering.py
Original file line number Diff line number Diff line change
@@ -148,7 +148,7 @@ def do_format_signature(
The same code, formatted.
"""
env = context.environment
# YORE: Bump 2: Replace `do_get_template(env, "signature")` with `"signature.html.jinja"`.
# YORE: Bump 2: Replace `do_get_template(env, "signature")` with `"signature.html.jinja"` within line.
template = env.get_template(do_get_template(env, "signature"))

if annotations is None:
@@ -208,7 +208,7 @@ def do_format_attribute(
The same code, formatted.
"""
env = context.environment
# YORE: Bump 2: Replace `do_get_template(env, "expression")` with `"expression.html.jinja"`.
# YORE: Bump 2: Replace `do_get_template(env, "expression")` with `"expression.html.jinja"` within line.
template = env.get_template(do_get_template(env, "expression"))
annotations = context.parent["config"].show_signature_annotations

@@ -399,7 +399,7 @@ def _keep_object(name: str, filters: Sequence[tuple[Pattern, bool]]) -> bool:
def do_filter_objects(
objects_dictionary: dict[str, Object | Alias],
*,
filters: Sequence[tuple[Pattern, bool]] | None = None,
filters: Sequence[tuple[Pattern, bool]] | Literal["public"] | None = None,
members_list: bool | list[str] | None = None,
inherited_members: bool | list[str] = False,
keep_no_docstrings: bool = True,
@@ -408,7 +408,7 @@ def do_filter_objects(
Parameters:
objects_dictionary: The dictionary of objects.
filters: Filters to apply, based on members' names.
filters: Filters to apply, based on members' names, or `"public"`.
Each element is a tuple: a pattern, and a boolean indicating whether
to reject the object if the pattern matches.
members_list: An optional, explicit list of members to keep.
@@ -449,7 +449,9 @@ def do_filter_objects(
]

# Use filters and docstrings.
if filters:
if filters == "public":
objects = [obj for obj in objects if obj.is_public]
elif filters:
objects = [
obj for obj in objects if _keep_object(obj.name, filters) or (inherited_members_specified and obj.inherited)
]
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ Context:
{% endif %}
{% with heading_level = heading_level + extra_level %}
{% for attribute in attributes|order_members(config.members_order, members_list) %}
{% if members_list is not none or (not attribute.is_imported or attribute.is_public) %}
{% if config.filters == "public" or members_list is not none or (not attribute.is_imported or attribute.is_public) %}
{% include attribute|get_template with context %}
{% endif %}
{% endfor %}
@@ -69,7 +69,7 @@ Context:
{% endif %}
{% with heading_level = heading_level + extra_level %}
{% for class in classes|order_members(config.members_order, members_list) %}
{% if members_list is not none or (not class.is_imported or class.is_public) %}
{% if config.filters == "public" or members_list is not none or (not class.is_imported or class.is_public) %}
{% include class|get_template with context %}
{% endif %}
{% endfor %}
@@ -90,7 +90,7 @@ Context:
{% with heading_level = heading_level + extra_level %}
{% for function in functions|order_members(config.members_order, members_list) %}
{% if not (obj.kind.value == "class" and function.name == "__init__" and config.merge_init_into_class) %}
{% if members_list is not none or (not function.is_imported or function.is_public) %}
{% if config.filters == "public" or members_list is not none or (not function.is_imported or function.is_public) %}
{% include function|get_template with context %}
{% endif %}
{% endif %}
@@ -112,7 +112,7 @@ Context:
{% endif %}
{% with heading_level = heading_level + extra_level %}
{% for module in modules|order_members("alphabetical", members_list) %}
{% if members_list is not none or (not module.is_alias or module.is_public) %}
{% if config.filters == "public" or members_list is not none or (not module.is_alias or module.is_public) %}
{% include module|get_template with context %}
{% endif %}
{% endfor %}
@@ -137,7 +137,7 @@ Context:

{% if not (obj.is_class and child.name == "__init__" and config.merge_init_into_class) %}

{% if members_list is not none or child.is_public %}
{% if config.filters == "public" or members_list is not none or child.is_public %}
{% if child.is_attribute %}
{% with attribute = child %}
{% include attribute|get_template with context %}
30 changes: 30 additions & 0 deletions tests/snapshots/__init__.py
Original file line number Diff line number Diff line change
@@ -353,5 +353,35 @@
("inherited_members", ()),
("members", ()),
): external("a185e216dc7b*.html"),
(("filters", "public"), ("inherited_members", ("method1",)), ("members", None)): external("6af55596d9c4*.html"),
(("filters", "public"), ("inherited_members", ("method1",)), ("members", False)): external(
"6abf5ddd819b*.html",
),
(("filters", "public"), ("inherited_members", ()), ("members", None)): external("6d72c524b827*.html"),
(("filters", "public"), ("inherited_members", False), ("members", False)): external("9dab67183389*.html"),
(("filters", "public"), ("inherited_members", ("method1",)), ("members", True)): external("6c0b7207df03*.html"),
(("filters", "public"), ("inherited_members", True), ("members", ())): external("f48d651b3f1a*.html"),
(("filters", "public"), ("inherited_members", ("method1",)), ("members", ("module_attribute",))): external(
"408244423577*.html",
),
(("filters", "public"), ("inherited_members", True), ("members", None)): external("16295fa51a2c*.html"),
(("filters", "public"), ("inherited_members", True), ("members", True)): external("37232379c426*.html"),
(("filters", "public"), ("inherited_members", ()), ("members", ())): external("2e866eca9a45*.html"),
(("filters", "public"), ("inherited_members", True), ("members", False)): external("ed5d07bcdbaa*.html"),
(("filters", "public"), ("inherited_members", False), ("members", ())): external("135f57223e00*.html"),
(("filters", "public"), ("inherited_members", False), ("members", None)): external("b4e20d5cd52e*.html"),
(("filters", "public"), ("inherited_members", ()), ("members", False)): external("46daa7e60b98*.html"),
(("filters", "public"), ("inherited_members", False), ("members", True)): external("a255ee80bf7a*.html"),
(("filters", "public"), ("inherited_members", ()), ("members", True)): external("74e2496015e1*.html"),
(("filters", "public"), ("inherited_members", True), ("members", ("module_attribute",))): external(
"e254ae60f9af*.html",
),
(("filters", "public"), ("inherited_members", ("method1",)), ("members", ())): external("51d73351dc55*.html"),
(("filters", "public"), ("inherited_members", ()), ("members", ("module_attribute",))): external(
"d56d3aeae22b*.html",
),
(("filters", "public"), ("inherited_members", False), ("members", ("module_attribute",))): external(
"80399c502938*.html",
),
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
{
"filters": "public",
"inherited_members": false,
"members": []
}
-->

<div class="doc doc-object doc-module">
<h1 class="doc doc-heading" id="members_package">
<code>
members_package
</code>
</h1>
<div class="doc doc-contents first">
<p>
Docstring for the package.
</p>
<div class="doc doc-children">
</div>
</div>
</div>
Loading