From bd86c87c38d58b9ca18241a75c4d28440c7ef150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Izurieta?= Date: Sun, 14 Apr 2019 00:24:59 +0200 Subject: Fix `AttributeError` when searching a remote by name Running code like `'origin' in git.Repo('path/to/existing/repository').remotes` raises an AttributeError instead of returning a boolean. This commit fixes that behaviour by catching the error when doing an identity match on `IterableList`. --- git/util.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'git/util.py') diff --git a/git/util.py b/git/util.py index 3ba58857..7ca0564e 100644 --- a/git/util.py +++ b/git/util.py @@ -864,9 +864,12 @@ class IterableList(list): def __contains__(self, attr): # first try identity match for performance - rval = list.__contains__(self, attr) - if rval: - return rval + try: + rval = list.__contains__(self, attr) + if rval: + return rval + except (AttributeError, TypeError): + pass # END handle match # otherwise make a full name search -- cgit v1.2.1