Skip to content

Commit 9746ffe

Browse files
committed
Allow __all__ to be tuple (which brings slight benefits)
1 parent 1adacac commit 9746ffe

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

flake8_dunder_all/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565
DALL000 = "DALL000 Module lacks __all__."
6666
DALL001 = "DALL001 __all__ not sorted alphabetically"
67-
DALL002 = "DALL002 __all__ not a list of strings."
67+
DALL002 = "DALL002 __all__ not a list or tuple of strings."
6868

6969

7070
class AlphabeticalOptions(Enum):
@@ -331,17 +331,17 @@ def run(self) -> Generator[Tuple[int, int, str, Type[Any]], None, None]:
331331
elif self.dunder_all_alphabetical == AlphabeticalOptions.IGNORE:
332332
# Alphabetical, upper or lower don't matter
333333
sorted_alphabetical = natsort.natsorted(visitor.all_members, key=str.lower)
334-
if visitor.all_members != sorted_alphabetical:
334+
if list(visitor.all_members) != sorted_alphabetical:
335335
yield visitor.all_lineno, 0, f"{DALL001}.", type(self)
336336
elif self.dunder_all_alphabetical == AlphabeticalOptions.UPPER:
337337
# Alphabetical, uppercase grouped first
338338
sorted_alphabetical = natsort.natsorted(visitor.all_members)
339-
if visitor.all_members != sorted_alphabetical:
339+
if list(visitor.all_members) != sorted_alphabetical:
340340
yield visitor.all_lineno, 0, f"{DALL001} (uppercase first).", type(self)
341341
elif self.dunder_all_alphabetical == AlphabeticalOptions.LOWER:
342342
# Alphabetical, lowercase grouped first
343343
sorted_alphabetical = natsort.natsorted(visitor.all_members, alg=natsort.ns.LOWERCASEFIRST)
344-
if visitor.all_members != sorted_alphabetical:
344+
if list(visitor.all_members) != sorted_alphabetical:
345345
yield visitor.all_lineno, 0, f"{DALL001} (lowercase first).", type(self)
346346

347347
elif not visitor.members:

tests/test_flake8_dunder_all.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ def test_plugin_alphabetical_not_list(source: str, dunder_all_alphabetical: Alph
234234
assert {"{}:{}: {}".format(*r) for r in plugin.run()} == {"1:0: DALL002 __all__ not a list of strings."}
235235

236236

237+
def test_plugin_alphabetical_tuple():
238+
plugin = Plugin(ast.parse("__all__ = ('bar',\n'foo')"))
239+
plugin.dunder_all_alphabetical = AlphabeticalOptions.IGNORE
240+
assert {"{}:{}: {}".format(*r) for r in plugin.run()} == set()
241+
242+
237243
@pytest.mark.parametrize(
238244
"source, members, found_all, last_import",
239245
[

0 commit comments

Comments
 (0)