Converts all attributes to @property methods in order to emulate frozen classes.
(self, attributes: list[DataclassAttribute])
| 748 | return all_attrs |
| 749 | |
| 750 | def _freeze(self, attributes: list[DataclassAttribute]) -> None: |
| 751 | """Converts all attributes to @property methods in order to |
| 752 | emulate frozen classes. |
| 753 | """ |
| 754 | info = self._cls.info |
| 755 | for attr in attributes: |
| 756 | # Classes that directly specify a dataclass_transform metaclass must be neither frozen |
| 757 | # non non-frozen per PEP681. Though it is surprising, this means that attributes from |
| 758 | # such a class must be writable even if the rest of the class hierarchy is frozen. This |
| 759 | # matches the behavior of Pyright (the reference implementation). |
| 760 | if attr.is_neither_frozen_nor_nonfrozen: |
| 761 | continue |
| 762 | |
| 763 | sym_node = info.names.get(attr.name) |
| 764 | if sym_node is not None: |
| 765 | var = sym_node.node |
| 766 | if isinstance(var, Var): |
| 767 | if var.is_final: |
| 768 | continue # do not turn `Final` attrs to `@property` |
| 769 | var.is_property = True |
| 770 | else: |
| 771 | var = attr.to_var(info) |
| 772 | var.info = info |
| 773 | var.is_property = True |
| 774 | var._fullname = info.fullname + "." + var.name |
| 775 | info.names[var.name] = SymbolTableNode(MDEF, var) |
| 776 | |
| 777 | def _propertize_callables( |
| 778 | self, attributes: list[DataclassAttribute], settable: bool = True |
no test coverage detected