-
Notifications
You must be signed in to change notification settings - Fork 190
Use module filepath basename sans ext in is_public #326
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
"""Python code parser.""" | ||
|
||
import logging | ||
import os.path | ||
import six | ||
import textwrap | ||
import tokenize as tk | ||
|
@@ -121,7 +122,8 @@ class Module(Definition): | |
|
||
@property | ||
def is_public(self): | ||
return not self.name.startswith('_') or self.name.startswith('__') | ||
module_name, _ = os.path.splitext(os.path.basename(self.name)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that I see this and the tests, I think the fix needs to be a little more complex, see How publicity is determined. We need to look at all the packages in this module's path to determine the publicity, something like def is_public(self):
def is_public_name(module_name):
return not module_name.startswith('_') or module_name.startswith('__')
return all(is_public_name(name) for name in self.name.split('.')) Also, I would appreciate a comment describing the logic here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like that except The tricky part is getting the module name. Particularly from absolute paths or relative ones run from within a package. Like if run pydocstyle in Can you confirm whether or not the following should all work and are correct?
I don't actually know how that would be implemented, I don't even want to think about namespace packages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those are some good points. I'm not sure. Perhaps we need to keep this as you implemented and document that the publicity logic only applies up to the module level. @shacharoo, do you want to weigh in? |
||
return not module_name.startswith('_') or module_name.startswith('__') | ||
|
||
def __str__(self): | ||
return 'at module level' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -485,6 +485,12 @@ def test_module_publicity(): | |
module = parser.parse(code, "__filepath") | ||
assert module.is_public | ||
|
||
module = parser.parse(code, "_directory/filepath") | ||
assert module.is_public | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my previous comment, this should be private. |
||
|
||
module = parser.parse(code, "directory/_filepath") | ||
assert not module.is_public | ||
|
||
|
||
def test_complex_module(): | ||
"""Test that a complex module is parsed correctly.""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The release notes should generally describe the changed behavior, not the implementation. This can be e.g., "Fixed an issue where module publicity was incorrectly determined by their top-level package" or something similar.
Also, please also include the issue number along with the PR number.