Skip to content

Commit 162ecd1

Browse files
authored
Use is_number_token instead of assertion (#3069)
1 parent 8c8675c commit 162ecd1

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/black/__init__.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from black.const import DEFAULT_LINE_LENGTH, DEFAULT_INCLUDES, DEFAULT_EXCLUDES
4141
from black.const import STDIN_PLACEHOLDER
4242
from black.nodes import STARS, syms, is_simple_decorator_expression
43-
from black.nodes import is_string_token
43+
from black.nodes import is_string_token, is_number_token
4444
from black.lines import Line, EmptyLineTracker
4545
from black.linegen import transform_line, LineGenerator, LN
4646
from black.comments import normalize_fmt_off
@@ -1245,8 +1245,7 @@ def get_features_used( # noqa: C901
12451245
if value_head in {'f"', 'F"', "f'", "F'", "rf", "fr", "RF", "FR"}:
12461246
features.add(Feature.F_STRINGS)
12471247

1248-
elif n.type == token.NUMBER:
1249-
assert isinstance(n, Leaf)
1248+
elif is_number_token(n):
12501249
if "_" in n.value:
12511250
features.add(Feature.NUMERIC_UNDERSCORES)
12521251

src/black/nodes.py

+4
Original file line numberDiff line numberDiff line change
@@ -854,3 +854,7 @@ def is_rpar_token(nl: NL) -> TypeGuard[Leaf]:
854854

855855
def is_string_token(nl: NL) -> TypeGuard[Leaf]:
856856
return nl.type == token.STRING
857+
858+
859+
def is_number_token(nl: NL) -> TypeGuard[Leaf]:
860+
return nl.type == token.NUMBER

0 commit comments

Comments
 (0)