From 162ecd1d2cf9471efefb5b61c17d28b73acb79a1 Mon Sep 17 00:00:00 2001 From: Marco Edward Gorelli Date: Sat, 11 Jun 2022 17:04:09 +0100 Subject: [PATCH] Use is_number_token instead of assertion (#3069) --- src/black/__init__.py | 5 ++--- src/black/nodes.py | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/black/__init__.py b/src/black/__init__.py index 8872102a6ea..4200066e882 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -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 @@ -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) diff --git a/src/black/nodes.py b/src/black/nodes.py index 918038f69ba..12f24b96687 100644 --- a/src/black/nodes.py +++ b/src/black/nodes.py @@ -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