Skip to content

Commit 57edfce

Browse files
Improve package detection (#253)
If a module has an `__path__` attribute it should be treated as a package even if it doesn't have any submodules.
1 parent 2e8f211 commit 57edfce

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

pybind11_stubgen/parser/mixins/parse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ def handle_module(
107107
elif isinstance(obj, TypeVar_):
108108
result.type_vars.append(obj)
109109
elif obj is None:
110-
pass
110+
if name == "__path__":
111+
result.is_package = True
111112
else:
112113
raise AssertionError()
113114

pybind11_stubgen/structs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,4 @@ class Module:
199199
imports: set[Import] = field_(default_factory=set)
200200
aliases: list[Alias] = field_(default_factory=list)
201201
type_vars: list[TypeVar_] = field_(default_factory=list)
202+
is_package: bool = field_(default=False)

pybind11_stubgen/writer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def write_module(
1616
):
1717
assert to.exists()
1818
assert to.is_dir()
19-
if module.sub_modules or sub_dir is not None:
19+
if module.sub_modules or module.is_package or sub_dir is not None:
2020
if sub_dir is None:
2121
sub_dir = Path(module.name)
2222
module_dir = to / sub_dir

0 commit comments

Comments
 (0)