Skip to content

Commit

Permalink
use is_name_token to resolve type:ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Dec 21, 2021
1 parent e025308 commit 385c605
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/black/linegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from black.mode import Mode
from black.mode import Feature

from blib2to3.pytree import Node, Leaf
from blib2to3.pytree import Node, Leaf, is_name_token
from blib2to3.pgen2 import token


Expand Down Expand Up @@ -137,7 +137,7 @@ def visit_stmt(
"""
normalize_invisible_parens(node, parens_after=parens)
for child in node.children:
if child.type == token.NAME and child.value in keywords: # type: ignore
if is_name_token(child) and child.value in keywords:
yield from self.line()

yield from self.visit(child)
Expand Down
9 changes: 9 additions & 0 deletions src/blib2to3/pytree.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
Set,
Iterable,
)
if sys.version_info >= (3, 10):
from typing import TypeGuard
else:
from typing_extensions import TypeGuard
from blib2to3.pgen2.grammar import Grammar
from blib2to3.pgen2 import token

__author__ = "Guido van Rossum <[email protected]>"

Expand Down Expand Up @@ -978,3 +983,7 @@ def generate_matches(
r.update(r0)
r.update(r1)
yield c0 + c1, r


def is_name_token(nl: NL) -> TypeGuard[Leaf]:
return nl.type == token.NAME

0 comments on commit 385c605

Please sign in to comment.