From bba120d906fc7f5c8a426de51fe730dbbc648298 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Tue, 10 Jun 2014 11:15:59 +0200 Subject: [PATCH] hasattr test for static analysis, it's a common idiom. --- test/static_analysis/try_except.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/static_analysis/try_except.py b/test/static_analysis/try_except.py index b8d18376..2347b295 100644 --- a/test/static_analysis/try_except.py +++ b/test/static_analysis/try_except.py @@ -49,3 +49,18 @@ try: #! 4 attribute-error str.not_existing except [AttributeError]: pass + + +# ----------------- +# kind of similar: hasattr +# ----------------- + +if hasattr(object, 'undefined'): + str.undefined + str.upper + #! 4 attribute-error + str.undefined2 +else: + str.upper + #! 4 attribute-error + str.undefined