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

Commit e416156

Browse files
authored
Merge pull request #227 from jdufresne/remove-all-warning
Remove warning when __all__ is a list
2 parents ae52b07 + 35077fa commit e416156

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

docs/snippets/publicity.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ a class called ``_Foo`` is considered private. A method ``bar`` in ``_Foo`` is
2525
also considered private since its parent is a private class, even though its
2626
name does not begin with a single underscore.
2727

28+
Modules are parsed to look if ``__all__`` is defined. If so, only those top
29+
level constructs are considered public. The parser looks for ``__all__``
30+
defined as a literal list or tuple. As the parser doesn't execute the module,
31+
any mutation of ``__all__`` will not be considered.
32+
2833

2934
How publicity affects error reports
3035
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -38,4 +43,4 @@ However, it is important to note that while docstring are optional for private
3843
construct, they are still required to adhere to your style guide. So if a
3944
private module `_foo.py` does not have a docstring, it will not generate a
4045
D100 error, but if it *does* have a docstring, that docstring might generate
41-
other errors.
46+
other errors.

src/pydocstyle/parser.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -382,18 +382,6 @@ def parse_all(self):
382382
self.consume(tk.OP)
383383
if self.current.value not in '([':
384384
raise AllError('Could not evaluate contents of __all__. ')
385-
if self.current.value == '[':
386-
sys.stdout.write(
387-
"{0} WARNING: __all__ is defined as a list, this means "
388-
"pydocstyle cannot reliably detect contents of the __all__ "
389-
"variable, because it can be mutated. Change __all__ to be "
390-
"an (immutable) tuple, to remove this warning. Note, "
391-
"pydocstyle uses __all__ to detect which definitions are "
392-
"public, to warn if public definitions are missing "
393-
"docstrings. If __all__ is a (mutable) list, pydocstyle "
394-
"cannot reliably assume its contents. pydocstyle will "
395-
"proceed assuming __all__ is not mutated.\n"
396-
.format(self.filename))
397385
self.consume(tk.OP)
398386

399387
self.all = []

src/tests/test_definitions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,8 @@ def test_pep257(test_case):
296296
assert isinstance(error, Error)
297297
results = set([(e.definition.name, e.message) for e in results])
298298
assert case_module.expectation.expected == results
299+
300+
301+
def test_parser_no_warning(capsys):
302+
parse(StringIO(source_alt), 'file_alt.py')
303+
assert capsys.readouterr() == ('', '')

0 commit comments

Comments
 (0)