Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Fix publicity of module in private package
Browse files Browse the repository at this point in the history
  • Loading branch information
gbroques committed Jul 20, 2020
1 parent c911e9f commit 123025c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/pydocstyle/parser.py
Expand Up @@ -119,7 +119,16 @@ def is_public(self):
This helps determine if it requires a docstring.
"""
module_name = Path(self.name).name
return not module_name.startswith('_') or module_name.startswith('__')
return (
not self._is_inside_private_package() and
(not module_name.startswith('_') or module_name.startswith('__'))
)

def _is_inside_private_package(self):
"""Return True if the module is inside a private package."""
path = Path(self.name)
package_names = path.parts[:-1]
return any([package.startswith('_') for package in package_names])

def __str__(self):
return 'at module level'
Expand Down
7 changes: 7 additions & 0 deletions src/tests/parser_test.py
Expand Up @@ -575,6 +575,13 @@ def test_module_publicity(parent_path):
module = parser.parse(code, str(parent_path / "filepath"))
assert module.is_public

module = parser.parse(code, str(parent_path / "_private_pkg" / "filepath"))
assert not module.is_public

module = parser.parse(code, str(
parent_path / "_private_pkg" / "some_pkg" / "filepath"))
assert not module.is_public

module = parser.parse(code, str(parent_path / "_filepath"))
assert not module.is_public

Expand Down

0 comments on commit 123025c

Please sign in to comment.