Skip to content

Commit 596b659

Browse files
committed
Allow TypeVar names to start with underscores
This is consistent with our CapWords-based N801 class name check, which shares a similar PEP 8 definition. Resolves #245
1 parent a6be839 commit 596b659

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/pep8ext_naming.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -537,13 +537,14 @@ def visit_module(self, node, parents: Sequence, ignored: NameSet):
537537
if func_name != "TypeVar" or name in ignored:
538538
continue
539539

540-
if len(args) == 0 or args[0] != name:
540+
if not args or args[0] != name:
541541
yield self.err(body, 'N808', name=name)
542542

543-
if not name[:1].isupper():
543+
stripped_name = name.lstrip('_')
544+
if not stripped_name[:1].isupper():
544545
yield self.err(body, 'N808', name=name)
545546

546-
parts = name.split('_')
547+
parts = stripped_name.split('_')
547548
if len(parts) > 2:
548549
yield self.err(body, 'N808', name=name)
549550

testsuite/N808.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
#: Okay
4343
Good = TypeVar("Good")
4444

45-
#: N808
46-
__NotGood = TypeVar("__NotGood")
45+
#: Okay
46+
__Good = TypeVar("__Good")
4747

4848
#: N808
4949
__NotGood__ = TypeVar("__NotGood__")

0 commit comments

Comments
 (0)