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

Commit bfe62e4

Browse files
committed
If a module starts with a single leading underscore, it is considered private.
1 parent 717f672 commit bfe62e4

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/pydocstyle/parser.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,14 @@ class Module(Definition):
103103
_fields = ('name', '_source', 'start', 'end', 'decorators', 'docstring',
104104
'children', 'parent', '_all', 'future_imports',
105105
'skipped_error_codes')
106-
is_public = True
107106
_nest = staticmethod(lambda s: {'def': Function, 'class': Class}[s])
108107
module = property(lambda self: self)
109108
all = property(lambda self: self._all)
110109

110+
@property
111+
def is_public(self):
112+
return not self.name.startswith('_') or self.name.startswith('__')
113+
111114
def __str__(self):
112115
return 'at module level'
113116

src/tests/parser_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,18 @@ def test_raise_from():
276276
parser = Parser()
277277
code = CodeSnippet("raise ValueError() from None")
278278
parser.parse(code, 'file_path')
279+
280+
281+
def test_module_publicity():
282+
"""Test that a module that has a single leading underscore is private."""
283+
parser = Parser()
284+
code = CodeSnippet("")
285+
286+
module = parser.parse(code, "filepath")
287+
assert module.is_public
288+
289+
module = parser.parse(code, "_filepath")
290+
assert not module.is_public
291+
292+
module = parser.parse(code, "__filepath")
293+
assert module.is_public

0 commit comments

Comments
 (0)