-
-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix __repr__ crashing when a member is uninitialized or deleted
- Loading branch information
Showing
3 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The ``__repr__`` set by ``attrs`` | ||
no longer produces an ``AttributeError`` | ||
when the instance is missing some of the specified attributes | ||
(either through deleting | ||
or after using ``init=False`` on some attributes). | ||
|
||
This can break code | ||
that relied on ``repr(attr_cls_instance)`` raising ``AttributeError`` | ||
to check if any attr-specified members were unset. | ||
|
||
If you were using this, | ||
you can implement a custom method for checking this:: | ||
|
||
def has_unset_members(self): | ||
for field in attr.fields(type(self)): | ||
try: | ||
getattr(self, field.name) | ||
except AttributeError: | ||
return True | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters