-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs_ex08_converters.output
More file actions
31 lines (25 loc) · 901 Bytes
/
docs_ex08_converters.output
File metadata and controls
31 lines (25 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
ConverterEx(unconverted='42', converted=42)
def __eq__(self, other):
if self is other:
return True
return (
self.unconverted == other.unconverted
and self.converted == other.converted
) if self.__class__ is other.__class__ else NotImplemented
def __init__(self, unconverted, converted):
self.unconverted = unconverted
self.converted = converted
def __replace__(self, /, **changes):
new_kwargs = {
'unconverted': self.unconverted,
'converted': self.converted,
}
new_kwargs |= changes
return self.__class__(**new_kwargs)
def __repr__(self):
return f'{type(self).__qualname__}(unconverted={self.unconverted!r}, converted={self.converted!r})'
def __setattr__(self, name, value):
if conv := _converters.get(name):
_object_setattr(self, name, conv(value))
else:
_object_setattr(self, name, value)