|
22 | 22 |
|
23 | 23 | # tag::MOVIE_TYPE_VALIDATION[] |
24 | 24 |
|
25 | | - >>> blockbuster = Movie(title='Avatar', year=2009, box_office='billions') |
| 25 | + >>> megahit = Movie(title='Avatar', year=2009, |
| 26 | + ... box_office='billions') |
26 | 27 | Traceback (most recent call last): |
27 | 28 | ... |
28 | 29 | TypeError: 'billions' is not compatible with box_office:float |
|
45 | 46 |
|
46 | 47 | Providing extra arguments to the constructor is not allowed:: |
47 | 48 |
|
48 | | - >>> blockbuster = Movie(title='Avatar', year=2009, box_office=2000, |
| 49 | + >>> megahit = Movie(title='Avatar', year=2009, box_office=2000, |
49 | 50 | ... director='James Cameron') |
50 | 51 | Traceback (most recent call last): |
51 | 52 | ... |
@@ -86,7 +87,8 @@ def __set__(self, instance: Any, value: Any) -> None: |
86 | 87 | value = self.constructor(value) # <5> |
87 | 88 | except (TypeError, ValueError) as e: # <6> |
88 | 89 | type_name = self.constructor.__name__ |
89 | | - msg = f'{value!r} is not compatible with {self.name}:{type_name}' |
| 90 | + msg = (f'{value!r} is not compatible with ' + |
| 91 | + f'{self.name}:{type_name}') |
90 | 92 | raise TypeError(msg) from e |
91 | 93 | instance.__dict__[self.name] = value # <7> |
92 | 94 | # end::CHECKED_FIELD[] |
@@ -124,7 +126,8 @@ def __flag_unknown_attrs(self, *names: str) -> NoReturn: # <5> |
124 | 126 | plural = 's' if len(names) > 1 else '' |
125 | 127 | extra = ', '.join(f'{name!r}' for name in names) |
126 | 128 | cls_name = repr(self.__class__.__name__) |
127 | | - raise AttributeError(f'{cls_name} object has no attribute{plural} {extra}') |
| 129 | + raise AttributeError(f'{cls_name} object has ' + |
| 130 | + f'no attribute{plural} {extra}') |
128 | 131 |
|
129 | 132 | def _asdict(self) -> dict[str, Any]: # <6> |
130 | 133 | return { |
|
0 commit comments