| 94 | |
| 95 | # tag::CHECKED_DECORATOR[] |
| 96 | def checked(cls: type) -> type: # <1> |
| 97 | for name, constructor in _fields(cls).items(): # <2> |
| 98 | setattr(cls, name, Field(name, constructor)) # <3> |
| 99 | |
| 100 | cls._fields = classmethod(_fields) # type: ignore # <4> |
| 101 | |
| 102 | instance_methods = ( # <5> |
| 103 | __init__, |
| 104 | __repr__, |
| 105 | __setattr__, |
| 106 | _asdict, |
| 107 | __flag_unknown_attrs, |
| 108 | ) |
| 109 | for method in instance_methods: # <6> |
| 110 | setattr(cls, method.__name__, method) |
| 111 | |
| 112 | return cls # <7> |
| 113 | # end::CHECKED_DECORATOR[] |
| 114 | |
| 115 | # tag::CHECKED_METHODS[] |