diff options
author | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2009-03-24 11:48:30 +0100 |
---|---|---|
committer | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2009-03-24 11:48:30 +0100 |
commit | 3e9d8e5bfac1ec9287c75cd8e1754d1749a2aa48 (patch) | |
tree | 229d7a726dcfd09f2e9834debe7ac16fd6ed3429 | |
parent | a387f48ebb3674f7d5359d77a673390ba32ee085 (diff) | |
download | astroid-git-3e9d8e5bfac1ec9287c75cd8e1754d1749a2aa48.tar.gz |
discard If branches if exceptions specified
-rw-r--r-- | infutils.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/infutils.py b/infutils.py index 55778f81..127a3846 100644 --- a/infutils.py +++ b/infutils.py @@ -80,6 +80,10 @@ class InferenceContext(object): def are_exclusive(stmt1, stmt2, exceptions=None): """return true if the two given statements are mutually exclusive + `exceptions` may be a list of exception names. If specified, discard If + branches and check one of the statement is in an exception handler catching + one of the given exceptions. + algorithm : 1) index stmt1's parents 2) climb among stmt2's parents until we find a common parent @@ -103,7 +107,7 @@ def are_exclusive(stmt1, stmt2, exceptions=None): if stmt1_parents.has_key(node): # if the common parent is a If or TryExcept statement, look if # nodes are in exclusive branchs - if isinstance(node, If): + if isinstance(node, If) and exceptions is None: if (node.locate_child(previous)[1] is not node.locate_child(children[node])[1]): return True |