Skip to content

Commit

Permalink
Use getattr() instead of hasattr() plus .member
Browse files Browse the repository at this point in the history
pylint 2.7.2 from Debian 11 (bullseye) complains:

```
************* Module apport.crashdb_impl.launchpad
apport/crashdb_impl/launchpad.py:179:22: E1101: Instance of 'Exception' has no 'content' member (no-member)
************* Module apport.ui
apport/ui.py:590:23: E1101: Instance of 'ValueError' has no 'errno' member (no-member)
```

Use `getattr()` directly instead of checking with `hasattr()` before
accessing the member.

Signed-off-by: Benjamin Drung <bdrung@ubuntu.com>
  • Loading branch information
bdrung committed Jun 30, 2022
1 parent 8b3cc8e commit 1842ba2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
6 changes: 1 addition & 5 deletions apport/crashdb_impl/launchpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,10 @@ def launchpad(self):
version="1.0",
)
except Exception as error:
if hasattr(error, "content"):
msg = error.content
else:
msg = str(error)
apport.error(
"connecting to Launchpad failed: %s\n"
'You can reset the credentials by removing the file "%s"',
msg,
getattr(error, "content", str(error)),
self.auth,
)
sys.exit(99) # transient error
Expand Down
5 changes: 2 additions & 3 deletions apport/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,11 +584,10 @@ def run_report_bug(self, symptom_script=None):
)
return False
except (ValueError, OSError) as error:
if hasattr(error, "errno"):
if getattr(error, "errno", None) == errno.ENOENT:
# silently ignore nonexisting PIDs; the user must not
# close the application prematurely
if error.errno == errno.ENOENT:
return False
return False
self.ui_error_message(
_("Invalid PID"),
_(
Expand Down

0 comments on commit 1842ba2

Please sign in to comment.