|
57 | 57 | import mypy.util
|
58 | 58 | import mypy.version
|
59 | 59 | from mypy.build import build
|
| 60 | +from mypy.constant_fold import constant_fold_expr |
60 | 61 | from mypy.errors import CompileError, Errors
|
61 | 62 | from mypy.find_sources import InvalidSourceList, create_source_list
|
62 | 63 | from mypy.modulefinder import (
|
@@ -1021,14 +1022,16 @@ def is_typed_namedtuple(self, expr: CallExpr) -> bool:
|
1021 | 1022 | def _get_namedtuple_fields(self, call: CallExpr) -> list[tuple[str, str]] | None:
|
1022 | 1023 | if self.is_namedtuple(call):
|
1023 | 1024 | fields_arg = call.args[1]
|
1024 |
| - if isinstance(fields_arg, StrExpr): |
1025 |
| - field_names = fields_arg.value.replace(",", " ").split() |
| 1025 | + folded = constant_fold_expr(fields_arg, "<unused>") |
| 1026 | + if isinstance(folded, str): |
| 1027 | + field_names = folded.replace(",", " ").split() |
1026 | 1028 | elif isinstance(fields_arg, (ListExpr, TupleExpr)):
|
1027 | 1029 | field_names = []
|
1028 | 1030 | for field in fields_arg.items:
|
1029 |
| - if not isinstance(field, StrExpr): |
| 1031 | + folded = constant_fold_expr(field, "<unused>") |
| 1032 | + if not isinstance(folded, str): |
1030 | 1033 | return None
|
1031 |
| - field_names.append(field.value) |
| 1034 | + field_names.append(folded) |
1032 | 1035 | else:
|
1033 | 1036 | return None # Invalid namedtuple fields type
|
1034 | 1037 | if field_names:
|
|
0 commit comments