diff --git a/docs/release_notes.rst b/docs/release_notes.rst index 01458c23..f4e7dd45 100644 --- a/docs/release_notes.rst +++ b/docs/release_notes.rst @@ -17,6 +17,7 @@ Bug Fixes * Detect inner asynchronous functions for D202 (#467) * Fix a bug in parsing Google-style argument description. The bug caused some argument names to go unreported in D417 (#448). +* Correctly detect publicity of modules inside directories (#470). 5.0.2 - January 8th, 2020 --------------------------- diff --git a/src/pydocstyle/parser.py b/src/pydocstyle/parser.py index 76b3dab7..8ee587b9 100644 --- a/src/pydocstyle/parser.py +++ b/src/pydocstyle/parser.py @@ -5,6 +5,7 @@ from itertools import chain, dropwhile from re import compile as re from io import StringIO +from pathlib import Path from .utils import log @@ -117,7 +118,8 @@ def is_public(self): This helps determine if it requires a docstring. """ - return not self.name.startswith('_') or self.name.startswith('__') + module_name = Path(self.name).name + return not module_name.startswith('_') or module_name.startswith('__') def __str__(self): return 'at module level' diff --git a/src/tests/parser_test.py b/src/tests/parser_test.py index 832d1b52..0f7af54b 100644 --- a/src/tests/parser_test.py +++ b/src/tests/parser_test.py @@ -1,6 +1,7 @@ """Parser tests.""" import io +import os import sys import pytest import textwrap @@ -562,18 +563,22 @@ def test_matrix_multiplication_with_decorators(code): assert inner_function.decorators[0].name == 'a' -def test_module_publicity(): +@pytest.mark.parametrize("parent_path", ( + os.path.join("some", "directory"), + "" +)) +def test_module_publicity(parent_path): """Test that a module that has a single leading underscore is private.""" parser = Parser() code = CodeSnippet("") - module = parser.parse(code, "filepath") + module = parser.parse(code, os.path.join(parent_path, "filepath")) assert module.is_public - module = parser.parse(code, "_filepath") + module = parser.parse(code, os.path.join(parent_path, "_filepath")) assert not module.is_public - module = parser.parse(code, "__filepath") + module = parser.parse(code, os.path.join(parent_path, "__filepath")) assert module.is_public