Does this rvalue need some special initializer value?
(self, rvalue: Expression)
| 1324 | return f"{self._indent}{lvalue}: {typename}{initializer}\n" |
| 1325 | |
| 1326 | def get_assign_initializer(self, rvalue: Expression) -> str: |
| 1327 | """Does this rvalue need some special initializer value?""" |
| 1328 | if not self._current_class: |
| 1329 | return "" |
| 1330 | # Current rules |
| 1331 | # 1. Return `...` if we are dealing with `NamedTuple` or `dataclass` field and |
| 1332 | # it has an existing default value |
| 1333 | if ( |
| 1334 | self._current_class.info |
| 1335 | and self._current_class.info.is_named_tuple |
| 1336 | and not isinstance(rvalue, TempNode) |
| 1337 | ): |
| 1338 | return " = ..." |
| 1339 | if self.processing_dataclass: |
| 1340 | if isinstance(rvalue, CallExpr): |
| 1341 | fullname = self.get_fullname(rvalue.callee) |
| 1342 | if fullname in (self.dataclass_field_specifier or DATACLASS_FIELD_SPECIFIERS): |
| 1343 | p = AliasPrinter(self) |
| 1344 | return f" = {rvalue.accept(p)}" |
| 1345 | if not (isinstance(rvalue, TempNode) and rvalue.no_rhs): |
| 1346 | return " = ..." |
| 1347 | # TODO: support other possible cases, where initializer is important |
| 1348 | |
| 1349 | # By default, no initializer is required: |
| 1350 | return "" |
| 1351 | |
| 1352 | def add_decorator(self, name: str, require_name: bool = False) -> None: |
| 1353 | if require_name: |
no test coverage detected