From c0dbd585bac9b1050192dc465a053c543b75442a Mon Sep 17 00:00:00 2001 From: "Oriol (ProDesk)" Date: Wed, 14 May 2025 10:44:23 +0200 Subject: [PATCH 1/3] update generator import to collections.abc --- src/docstub/_docstrings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/docstub/_docstrings.py b/src/docstub/_docstrings.py index 52bc59a..9a92bfe 100644 --- a/src/docstub/_docstrings.py +++ b/src/docstub/_docstrings.py @@ -114,7 +114,7 @@ def as_generator(cls, *, yield_types, receive_types=(), return_types=()): value = f"{value}, {return_annotation.value}" value = f"Generator[{value}]" - imports |= {KnownImport(import_path="typing", import_name="Generator")} + imports |= {KnownImport(import_path="collections.abc", import_name="Generator")} generator = cls(value=value, imports=imports) return generator From b346f28b1df1d230227c720a7630070688f85c09 Mon Sep 17 00:00:00 2001 From: "Oriol (ProDesk)" Date: Wed, 14 May 2025 10:49:59 +0200 Subject: [PATCH 2/3] update generator tests --- tests/test_docstrings.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_docstrings.py b/tests/test_docstrings.py index 90e766f..cebfcb0 100644 --- a/tests/test_docstrings.py +++ b/tests/test_docstrings.py @@ -22,7 +22,7 @@ def test_as_return_tuple(self): sequence_anno = Annotation( value="Sequence", imports=frozenset( - {KnownImport(import_name="Sequence", import_path="typing")} + {KnownImport(import_name="Sequence", import_path="collections.abc")} ), ) return_annotation = Annotation.many_as_tuple([path_anno, sequence_anno]) @@ -244,7 +244,7 @@ def test_yields(self, caplog): annotations = DocstringAnnotations(docstring, transformer=transformer) assert annotations.returns.value == "Generator[tuple[int, str]]" assert annotations.returns.imports == { - KnownImport(import_path="typing", import_name="Generator") + KnownImport(import_path="collections.abc", import_name="Generator") } def test_receives(self, caplog): @@ -268,7 +268,7 @@ def test_receives(self, caplog): == "Generator[tuple[int, str], tuple[float, bytes]]" ) assert annotations.returns.imports == { - KnownImport(import_path="typing", import_name="Generator") + KnownImport(import_path="collections.abc", import_name="Generator") } def test_full_generator(self, caplog): @@ -295,7 +295,7 @@ def test_full_generator(self, caplog): "Generator[tuple[int, str], tuple[float, bytes], bool]" ) assert annotations.returns.imports == { - KnownImport(import_path="typing", import_name="Generator") + KnownImport(import_path="collections.abc", import_name="Generator") } def test_yields_and_returns(self, caplog): @@ -315,7 +315,7 @@ def test_yields_and_returns(self, caplog): annotations = DocstringAnnotations(docstring, transformer=transformer) assert annotations.returns.value == ("Generator[tuple[int, str], None, bool]") assert annotations.returns.imports == { - KnownImport(import_path="typing", import_name="Generator") + KnownImport(import_path="collections.abc", import_name="Generator") } def test_duplicate_parameters(self, caplog): From c1453673e48e67febf6a945dad5be4f05baa28ed Mon Sep 17 00:00:00 2001 From: "Oriol (ProDesk)" Date: Wed, 14 May 2025 10:50:09 +0200 Subject: [PATCH 3/3] update Callable import --- src/docstub/default_config.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/docstub/default_config.toml b/src/docstub/default_config.toml index 05ded60..c6b0f6c 100644 --- a/src/docstub/default_config.toml +++ b/src/docstub/default_config.toml @@ -18,7 +18,7 @@ extend_grammar = """ # defaults to "false" [tool.docstub.known_imports] Path = { from = "pathlib" } -Callable = { from = "typing" } +Callable = { from = "collections.abc" } np = { import = "numpy", as = "np" } NDArray = { from = "numpy.typing" } ArrayLike = { from = "numpy.typing" }