aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2020-03-11 14:41:26 -0700
committerJussi Pakkanen <jpakkane@gmail.com>2020-03-15 22:30:19 +0200
commit1bb66d15684aa694b88a62e33159f8cfee16ef25 (patch)
treee7049dd4397ec7b09b2065fea85b007a14334a33 /mesonbuild
parent79198de6cf012e681b436f8bcea4230c2979841c (diff)
downloadmeson-1bb66d15684aa694b88a62e33159f8cfee16ef25.zip
meson-1bb66d15684aa694b88a62e33159f8cfee16ef25.tar.gz
meson-1bb66d15684aa694b88a62e33159f8cfee16ef25.tar.bz2
fix conversion of hasattr to getattr
getattr() requires a default (return if missing) value or it raises an AttributeError. In a few cases I changed hasattr to getattr and didn't set a default value, so those cases could except. This corrects that.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/interpreterbase.py2
-rw-r--r--mesonbuild/mlog.py2
2 files changed, 2 insertions, 2 deletions
diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py
index b8008b0..a3acc75 100644
--- a/mesonbuild/interpreterbase.py
+++ b/mesonbuild/interpreterbase.py
@@ -446,7 +446,7 @@ class InterpreterBase:
self.current_lineno = cur.lineno
self.evaluate_statement(cur)
except Exception as e:
- if getattr(e, 'lineno') is None:
+ if getattr(e, 'lineno', None) is None:
# We are doing the equivalent to setattr here and mypy does not like it
e.lineno = cur.lineno # type: ignore
e.colno = cur.colno # type: ignore
diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py
index 88a47e7..7d9dc16 100644
--- a/mesonbuild/mlog.py
+++ b/mesonbuild/mlog.py
@@ -298,7 +298,7 @@ def exception(e: Exception, prefix: T.Optional[AnsiDecorator] = None) -> None:
prefix = red('ERROR:')
log()
args = [] # type: T.List[T.Union[AnsiDecorator, str]]
- if getattr(e, 'file') is not None and getattr(e, 'lineno') is not None and getattr(e, 'colno') is not None:
+ if all(getattr(e, a, None) is not None for a in ['file', 'lineno', 'colno']):
# Mypy doesn't follow hasattr, and it's pretty easy to visually inspect
# that this is correct, so we'll just ignore it.
path = get_relative_path(Path(e.file), Path(os.getcwd())) # type: ignore