Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/docstub/_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/docstub/default_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
10 changes: 5 additions & 5 deletions tests/test_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down