Skip to content

Instantly share code, notes, and snippets.

@SmartManoj
Created January 10, 2025 10:33
Show Gist options
  • Save SmartManoj/53f6c99c897cfa0a5d82626967b41591 to your computer and use it in GitHub Desktop.
Save SmartManoj/53f6c99c897cfa0a5d82626967b41591 to your computer and use it in GitHub Desktop.
diff --git a/astroid/nodes/node_classes.py b/astroid/nodes/node_classes.py
index c1c7af36..6d1aa5d7 100644
--- a/astroid/nodes/node_classes.py
+++ b/astroid/nodes/node_classes.py
@@ -4692,14 +4692,18 @@ class FormattedValue(NodeNG):
yield util.Uninferable
uninferable_already_generated = True
continue
- formatted = format(value.value, format_spec.value)
- yield Const(
- formatted,
- lineno=self.lineno,
- col_offset=self.col_offset,
- end_lineno=self.end_lineno,
- end_col_offset=self.end_col_offset,
- )
+
+ if value.value is not None and format_spec.value is not None:
+ yield Const(
+ format(value.value, format_spec.value),
+ lineno=self.lineno,
+ col_offset=self.col_offset,
+ end_lineno=self.end_lineno,
+ end_col_offset=self.end_col_offset,
+ )
+ else:
+ # Handle the None case, e.g., yield an error or a default value
+ yield util.Uninferable
MISSING_VALUE = "{MISSING_VALUE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment