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

Fix Module.is_public() when the module is not a the root #470

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release_notes.rst
Expand Up @@ -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
---------------------------
Expand Down
4 changes: 3 additions & 1 deletion src/pydocstyle/parser.py
Expand Up @@ -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

Expand Down Expand Up @@ -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'
Expand Down
13 changes: 9 additions & 4 deletions src/tests/parser_test.py
@@ -1,6 +1,7 @@
"""Parser tests."""

import io
import os
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use pathlib in this file, too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in PR #494.

import sys
import pytest
import textwrap
Expand Down Expand Up @@ -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


Expand Down