diff options
author | syt <syt@sextans.logilab.fr> | 2006-05-09 09:55:16 +0200 |
---|---|---|
committer | syt <syt@sextans.logilab.fr> | 2006-05-09 09:55:16 +0200 |
commit | b3a23e3f94f7468015a4cde78b58b5ebee0bb308 (patch) | |
tree | 3172117dc612e948d4d4f2eebf2e9e78c1d45099 /checkers/utils.py | |
parent | a120206e378545016e1b480724ee9b53e875f85b (diff) | |
download | pylint-b3a23e3f94f7468015a4cde78b58b5ebee0bb308.tar.gz |
check ChangeLog
Diffstat (limited to 'checkers/utils.py')
-rw-r--r-- | checkers/utils.py | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/checkers/utils.py b/checkers/utils.py index cb3a99b..8c6612a 100644 --- a/checkers/utils.py +++ b/checkers/utils.py @@ -1,6 +1,6 @@ # pylint: disable-msg=W0611 # -# Copyright (c) 2003-2005 LOGILAB S.A. (Paris, FRANCE). +# Copyright (c) 2003-2006 LOGILAB S.A. (Paris, FRANCE). # http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This program is free software; you can redistribute it and/or modify it under @@ -30,6 +30,30 @@ except AttributeError: COMP_NODE_TYPES = astng.ListComp FOR_NODE_TYPES = (astng.For, astng.ListCompFor) +def safe_infer(node): + """return the infered value for the given node. + Return None if inference failed or if there is some ambiguity (more than + one node has been infered) + """ + try: + inferit = node.infer() + value = inferit.next() + except astng.InferenceError: + return + try: + inferit.next() + return # None if there is ambiguity on the infered node + except StopIteration: + return value + +def is_super(node): + """return True if the node is referencing the "super" builtin function + """ + if getattr(node, 'name', None) == 'super' and \ + node.root().name == '__builtin__': + return True + return False + def is_error(node): """return true if the function does nothing but raising an exception""" for child_node in node.code.getChildNodes(): @@ -37,6 +61,14 @@ def is_error(node): return True return False +def is_raising(stmt): + """return true if the given statement node raise an exception + """ + for node in stmt.nodes: + if isinstance(node, astng.Raise): + return True + return False + def is_empty(node): """return true if the given node does nothing but 'pass'""" for child_node in node.getChildNodes(): @@ -142,3 +174,11 @@ def overrides_a_method(class_node, name): if name in ancestor and isinstance(ancestor[name], astng.Function): return True return False + +def display_type(node): + """return the type of this node for screen display""" + if isinstance(node, astng.Instance): + return 'Instance of' + elif isinstance(node, astng.Module): + return 'Module' + return 'Class' |