Skip to content

Commit

Permalink
Use is_number_token instead of assertion (#3069)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Jun 11, 2022
1 parent 8c8675c commit 162ecd1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/black/__init__.py
Expand Up @@ -40,7 +40,7 @@
from black.const import DEFAULT_LINE_LENGTH, DEFAULT_INCLUDES, DEFAULT_EXCLUDES
from black.const import STDIN_PLACEHOLDER
from black.nodes import STARS, syms, is_simple_decorator_expression
from black.nodes import is_string_token
from black.nodes import is_string_token, is_number_token
from black.lines import Line, EmptyLineTracker
from black.linegen import transform_line, LineGenerator, LN
from black.comments import normalize_fmt_off
Expand Down Expand Up @@ -1245,8 +1245,7 @@ def get_features_used( # noqa: C901
if value_head in {'f"', 'F"', "f'", "F'", "rf", "fr", "RF", "FR"}:
features.add(Feature.F_STRINGS)

elif n.type == token.NUMBER:
assert isinstance(n, Leaf)
elif is_number_token(n):
if "_" in n.value:
features.add(Feature.NUMERIC_UNDERSCORES)

Expand Down
4 changes: 4 additions & 0 deletions src/black/nodes.py
Expand Up @@ -854,3 +854,7 @@ def is_rpar_token(nl: NL) -> TypeGuard[Leaf]:

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


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

0 comments on commit 162ecd1

Please sign in to comment.