griffecli 2.2.0__tar.gz → 2.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,40 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  <!-- insertion marker -->
8
+ ## [2.3.0](https://github.com/mkdocstrings/griffe/releases/tag/2.3.0) - 2026-09-04
9
+
10
+ <small>[Compare with 2.2.0](https://github.com/mkdocstrings/griffe/compare/2.2.0...2.3.0)</small>
11
+
12
+ ### Features
13
+
14
+ - Add option to give precedence to docstrings in stubs vs. source ([09a2a13](https://github.com/mkdocstrings/griffe/commit/09a2a1323d1b4d022a4ce76a9f2839287b9c100e) by Timothée Mazzucotelli). [Issue-447](https://github.com/mkdocstrings/griffe/issues/447), [PR-481](https://github.com/mkdocstrings/griffe/pull/481)
15
+
16
+ ### Bug Fixes
17
+
18
+ - Preserve nested tuple parentheses ([e095a7c](https://github.com/mkdocstrings/griffe/commit/e095a7cd4c239abd961f7899d7ddb17ea27caead) by Alperen). [PR-487](https://github.com/mkdocstrings/griffe/pull/487), Co-authored-by: Timothée Mazzucotelli <dev@pawamoy.fr>
19
+ - Preserve nested f-string format specs ([38921b7](https://github.com/mkdocstrings/griffe/commit/38921b70e3dbba9a493aa5117f11a3a7883634cf) by Alperen). [PR-486](https://github.com/mkdocstrings/griffe/pull/486)
20
+ - Disable all docstring warnings when passing `warnings=False` ([5cb0ae2](https://github.com/mkdocstrings/griffe/commit/5cb0ae2f00748288c4009c1d4b6ee19f6aca6b76) by Timothée Mazzucotelli).
21
+
22
+ ### Performance Improvements
23
+
24
+ - Reuse computed parent in `is_imported` ([092ac31](https://github.com/mkdocstrings/griffe/commit/092ac3162e1477a4b62eb875365996998adbd77d) by Timothée Mazzucotelli).
25
+ - Only build debug messages at debug level ([8f05a4a](https://github.com/mkdocstrings/griffe/commit/8f05a4ae5587d685bea1b0c98294a047b56c8df0) by Timothée Mazzucotelli).
26
+ - Avoid creating new sets when handling labels ([06cd02e](https://github.com/mkdocstrings/griffe/commit/06cd02e63c240286d11450887cc01b0ef76d8908) by Timothée Mazzucotelli).
27
+ - Maintain map of AST node type to visitor function ([e21851e](https://github.com/mkdocstrings/griffe/commit/e21851e732782823006223a7f5f8111b4200a257) by Timothée Mazzucotelli).
28
+ - Avoid cyclic refs in ASTs to allow garbage-collecting them ([b968de0](https://github.com/mkdocstrings/griffe/commit/b968de091afc1a4fd241f457538433ce3ada7520) by Timothée Mazzucotelli).
29
+ - Cache per-module path-related properties during serialization ([8bd6cc4](https://github.com/mkdocstrings/griffe/commit/8bd6cc4b34e96fc8235271cfa93a1a6a77091707) by Timothée Mazzucotelli).
30
+ - Do not fire load events when no extension has hooked them ([0e2ae7c](https://github.com/mkdocstrings/griffe/commit/0e2ae7c8cd1563d6dcca7a6c37fb8f2ec072cb24) by Timothée Mazzucotelli).
31
+ - Compute costly message lazily in alias resolution errors ([1e391b8](https://github.com/mkdocstrings/griffe/commit/1e391b8239747bb62908819e55468a961ffbaa99) by Timothée Mazzucotelli).
32
+ - Avoid iterating many times over function parameters when merging stubs ([03cae74](https://github.com/mkdocstrings/griffe/commit/03cae743e02c56af7375ffbfa70d6acf02e5491d) by Timothée Mazzucotelli).
33
+ - Avoid iterating many times over function parameters when diff'ing ([d3cf2c4](https://github.com/mkdocstrings/griffe/commit/d3cf2c41bb5f734e57b612b42d178e87af605ae8) by Timothée Mazzucotelli).
34
+ - Improve efficiency of AST parameter extraction ([1e37cd4](https://github.com/mkdocstrings/griffe/commit/1e37cd488d6adf55065b3ce4e7932faf1ff7d186) by Timothée Mazzucotelli).
35
+ - Cache serializable expression fields ([f9e48c1](https://github.com/mkdocstrings/griffe/commit/f9e48c16ebaeb719d5768cb921637aebe377a639) by Timothée Mazzucotelli).
36
+ - Use maps to make JSON encoder faster ([b7de96f](https://github.com/mkdocstrings/griffe/commit/b7de96fb516218ae3bf6a8e6d014a223df67f4a3) by Timothée Mazzucotelli).
37
+ - Avoid recomputing inherited members when diff'ing ([a29e028](https://github.com/mkdocstrings/griffe/commit/a29e028ff034752ff747dda17f3f875f22c2a192) by Timothée Mazzucotelli).
38
+ - Make Google, Numpy and Sphinx docstring parsers faster ([7f39373](https://github.com/mkdocstrings/griffe/commit/7f39373f8da779fb104dd2b6c11a02d95da628c4) by Timothée Mazzucotelli).
39
+ - Pre-compile patterns for docstring style detection ([ad58ad5](https://github.com/mkdocstrings/griffe/commit/ad58ad5b86390a8a02311189315dd4f59e0300a4) by Timothée Mazzucotelli).
40
+ - LRU-cache parsing of type annotations in docstrings ([1671e59](https://github.com/mkdocstrings/griffe/commit/1671e59fb675e9b45338956ce8aa5f5e56692690) by Timothée Mazzucotelli).
41
+
8
42
  ## [2.2.0](https://github.com/mkdocstrings/griffe/releases/tag/2.2.0) - 2026-08-16
9
43
 
10
44
  <small>[Compare with 2.1.0](https://github.com/mkdocstrings/griffe/compare/2.1.0...2.2.0)</small>
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: griffecli
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: Signatures for entire Python programs. Extract the structure, the frame, the skeleton of your project, to generate API documentation or find breaking changes in your API.
5
5
  Author-email: Timothée Mazzucotelli <dev@pawamoy.fr>
6
6
  License-Expression: ISC
@@ -22,4 +22,4 @@ Classifier: Topic :: Utilities
22
22
  Classifier: Typing :: Typed
23
23
  Requires-Python: >=3.10
24
24
  Requires-Dist: colorama>=0.4
25
- Requires-Dist: griffelib==2.2.0
25
+ Requires-Dist: griffelib==2.3.0
@@ -91,6 +91,7 @@ def _load_packages(
91
91
  force_inspection: bool = False,
92
92
  store_source: bool = True,
93
93
  find_stubs_package: bool = False,
94
+ prefer_stubs_docs: bool = False,
94
95
  ) -> GriffeLoader:
95
96
  from griffe._internal.loader import GriffeLoader # noqa: PLC0415
96
97
  from griffe._internal.logger import logger # noqa: PLC0415
@@ -104,6 +105,7 @@ def _load_packages(
104
105
  allow_inspection=allow_inspection,
105
106
  force_inspection=force_inspection,
106
107
  store_source=store_source,
108
+ prefer_stubs_docs=prefer_stubs_docs,
107
109
  )
108
110
 
109
111
  # Load each package.
@@ -192,6 +194,14 @@ def get_parser() -> argparse.ArgumentParser:
192
194
  default=False,
193
195
  help="Whether to look for stubs-only packages and merge them with concrete ones.",
194
196
  )
197
+ loading_options.add_argument(
198
+ "-P",
199
+ "--prefer-stubs-docstrings",
200
+ dest="prefer_stubs_docs",
201
+ action="store_true",
202
+ default=False,
203
+ help="Whether to prefer docstrings from stubs over those from sources.",
204
+ )
195
205
  loading_options.add_argument(
196
206
  "-e",
197
207
  "--extensions",
@@ -358,6 +368,7 @@ def dump(
358
368
  resolve_external: bool | None = None,
359
369
  search_paths: Sequence[str | Path] | None = None,
360
370
  find_stubs_package: bool = False,
371
+ prefer_stubs_docs: bool = False,
361
372
  append_sys_path: bool = False,
362
373
  allow_inspection: bool = True,
363
374
  force_inspection: bool = False,
@@ -380,6 +391,7 @@ def dump(
380
391
  find_stubs_package: Whether to search for stubs-only packages.
381
392
  If both the package and its stubs are found, they'll be merged together.
382
393
  If only the stubs are found, they'll be used as the package itself.
394
+ prefer_stubs_docs: Whether to give precedence to docstrings from stubs over those from sources.
383
395
  append_sys_path: Whether to append the contents of `sys.path` to the search paths.
384
396
  allow_inspection: Whether to allow inspecting modules when visiting them is not possible.
385
397
  force_inspection: Whether to force using dynamic analysis when loading data.
@@ -422,6 +434,7 @@ def dump(
422
434
  force_inspection=force_inspection,
423
435
  store_source=False,
424
436
  find_stubs_package=find_stubs_package,
437
+ prefer_stubs_docs=prefer_stubs_docs,
425
438
  )
426
439
  data_packages = loader.modules_collection.members
427
440
 
@@ -454,6 +467,7 @@ def check(
454
467
  search_paths: Sequence[str | Path] | None = None,
455
468
  append_sys_path: bool = False,
456
469
  find_stubs_package: bool = False,
470
+ prefer_stubs_docs: bool = False,
457
471
  allow_inspection: bool = True,
458
472
  force_inspection: bool = False,
459
473
  verbose: bool = False,
@@ -470,6 +484,8 @@ def check(
470
484
  extensions: The extensions to use.
471
485
  search_paths: The paths to search into.
472
486
  append_sys_path: Whether to append the contents of `sys.path` to the search paths.
487
+ find_stubs_package: Whether to search for stubs-only packages.
488
+ prefer_stubs_docs: Whether to give precedence to docstrings from stubs over those from sources.
473
489
  allow_inspection: Whether to allow inspecting modules when visiting them is not possible.
474
490
  force_inspection: Whether to force using dynamic analysis when loading data.
475
491
  verbose: Use a verbose output.
@@ -509,6 +525,7 @@ def check(
509
525
  allow_inspection=allow_inspection,
510
526
  force_inspection=force_inspection,
511
527
  find_stubs_package=find_stubs_package,
528
+ prefer_stubs_docs=prefer_stubs_docs,
512
529
  resolve_aliases=True,
513
530
  resolve_external=None,
514
531
  )
@@ -530,6 +547,7 @@ def check(
530
547
  allow_inspection=allow_inspection,
531
548
  force_inspection=force_inspection,
532
549
  find_stubs_package=find_stubs_package,
550
+ prefer_stubs_docs=prefer_stubs_docs,
533
551
  resolve_aliases=True,
534
552
  resolve_external=None,
535
553
  )
@@ -553,6 +571,7 @@ def check(
553
571
  allow_inspection=allow_inspection,
554
572
  force_inspection=force_inspection,
555
573
  find_stubs_package=find_stubs_package,
574
+ prefer_stubs_docs=prefer_stubs_docs,
556
575
  resolve_aliases=True,
557
576
  resolve_external=None,
558
577
  )
@@ -567,6 +586,7 @@ def check(
567
586
  allow_inspection=allow_inspection,
568
587
  force_inspection=force_inspection,
569
588
  find_stubs_package=find_stubs_package,
589
+ prefer_stubs_docs=prefer_stubs_docs,
570
590
  resolve_aliases=True,
571
591
  resolve_external=None,
572
592
  )
@@ -579,6 +599,7 @@ def check(
579
599
  allow_inspection=allow_inspection,
580
600
  force_inspection=force_inspection,
581
601
  find_stubs_package=find_stubs_package,
602
+ prefer_stubs_docs=prefer_stubs_docs,
582
603
  resolve_aliases=True,
583
604
  resolve_external=None,
584
605
  )
@@ -18,13 +18,18 @@
18
18
 
19
19
  from __future__ import annotations
20
20
 
21
+ import json
21
22
  import sys
23
+ from typing import TYPE_CHECKING
22
24
 
23
25
  import pytest
24
26
 
25
27
  from griffe._internal import debug
26
28
  from griffecli._internal import cli
27
29
 
30
+ if TYPE_CHECKING:
31
+ from pathlib import Path
32
+
28
33
 
29
34
  def test_main() -> None:
30
35
  """Basic CLI test."""
@@ -34,6 +39,26 @@ def test_main() -> None:
34
39
  assert cli.main(["dump", "griffe", "-s", "src", "-o/dev/null"]) == 0
35
40
 
36
41
 
42
+ @pytest.mark.parametrize("flag", ["-P", "--prefer-stubs-docstrings"])
43
+ def test_prefer_stubs_docstrings(tmp_path: Path, flag: str) -> None:
44
+ """Prefer docstrings from stubs when requested.
45
+
46
+ Parameters:
47
+ tmp_path: Pytest fixture providing a temporary directory.
48
+ flag: Short or long spelling of the CLI flag.
49
+ """
50
+ package_path = tmp_path / "package"
51
+ package_path.mkdir()
52
+ package_path.joinpath("__init__.py").write_text('"""Source."""', encoding="utf8")
53
+ package_path.joinpath("__init__.pyi").write_text('"""Stubs."""', encoding="utf8")
54
+ output_path = tmp_path / "output.json"
55
+
56
+ assert cli.main(["dump", str(package_path), flag, "-o", str(output_path)]) == 0
57
+
58
+ output = json.loads(output_path.read_text(encoding="utf8"))
59
+ assert output["package"]["docstring"]["value"] == "Stubs."
60
+
61
+
37
62
  def test_show_help(capsys: pytest.CaptureFixture) -> None:
38
63
  """Show help.
39
64
 
File without changes
File without changes
File without changes
File without changes
File without changes