Skip to content

Commit

Permalink
feat: Expose module properties on all objects
Browse files Browse the repository at this point in the history
Issue #226: #226
  • Loading branch information
pawamoy committed Jan 14, 2024
1 parent 8c57354 commit 123f8c5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/griffe/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,31 @@ def is_attribute(self) -> bool:
"""Whether this object is an attribute."""
return self.kind is Kind.ATTRIBUTE

@property
def is_init_module(self) -> bool:
"""Whether this object is an `__init__.py` module."""
return False

@property
def is_package(self) -> bool:
"""Whether this object is a package (top module)."""
return False

@property
def is_subpackage(self) -> bool:
"""Whether this object is a subpackage."""
return False

@property
def is_namespace_package(self) -> bool:
"""Whether this object is a namespace package (top folder, no `__init__.py`)."""
return False

@property
def is_namespace_subpackage(self) -> bool:
"""Whether this object is a namespace subpackage."""
return False

def has_labels(self, labels: set[str]) -> bool:
"""Tell if this object has all the given labels.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def test_stop_at_first_package_inside_namespace_package() -> None:
assert "d" in c_package.members

d_package = c_package.members["d"]
assert d_package.is_subpackage # type: ignore[union-attr]
assert d_package.is_subpackage
assert d_package.filepath == tmp_ns1.tmpdir.joinpath("a/b/c/d/__init__.py")
assert "mod1" in d_package.members
assert "mod2" not in d_package.members
Expand Down

0 comments on commit 123f8c5

Please sign in to comment.