diff options
-rw-r--r-- | astroid/__init__.py | 2 | ||||
-rw-r--r-- | astroid/astpeephole.py | 2 | ||||
-rw-r--r-- | astroid/bases.py | 12 | ||||
-rw-r--r-- | astroid/inference.py | 4 | ||||
-rw-r--r-- | astroid/manager.py | 6 | ||||
-rw-r--r-- | astroid/modutils.py | 6 | ||||
-rw-r--r-- | astroid/node_classes.py | 6 | ||||
-rw-r--r-- | astroid/nodes.py | 25 | ||||
-rw-r--r-- | astroid/protocols.py | 6 | ||||
-rw-r--r-- | astroid/raw_building.py | 10 | ||||
-rw-r--r-- | astroid/scoped_nodes.py | 25 | ||||
-rw-r--r-- | astroid/tests/unittest_builder.py | 9 | ||||
-rw-r--r-- | astroid/tests/unittest_inference.py | 389 | ||||
-rw-r--r-- | astroid/tests/unittest_manager.py | 10 | ||||
-rw-r--r-- | astroid/tests/unittest_modutils.py | 4 | ||||
-rw-r--r-- | astroid/tests/unittest_nodes.py | 2 | ||||
-rw-r--r-- | astroid/tests/unittest_raw_building.py | 2 | ||||
-rw-r--r-- | astroid/tests/unittest_regrtest.py | 2 | ||||
-rw-r--r-- | astroid/tests/unittest_scoped_nodes.py | 1 | ||||
-rw-r--r-- | pylintrc | 8 |
20 files changed, 266 insertions, 265 deletions
diff --git a/astroid/__init__.py b/astroid/__init__.py index d4fd12c..1ac98b9 100644 --- a/astroid/__init__.py +++ b/astroid/__init__.py @@ -47,6 +47,8 @@ from operator import attrgetter # WARNING: internal imports order matters ! +# pylint: disable=redefined-builtin, wildcard-import + # make all exception classes accessible from astroid package from astroid.exceptions import * diff --git a/astroid/astpeephole.py b/astroid/astpeephole.py index af03462..4616887 100644 --- a/astroid/astpeephole.py +++ b/astroid/astpeephole.py @@ -77,7 +77,7 @@ class ASTPeepholeOptimizer(object): # If we have inconsistent types, bail out. known = type(ast_nodes[0]) - if any(type(element) is not known + if any(not isinstance(element, known) for element in ast_nodes[1:]): return diff --git a/astroid/bases.py b/astroid/bases.py index b474df3..9c9e4de 100644 --- a/astroid/bases.py +++ b/astroid/bases.py @@ -388,8 +388,6 @@ class NodeNG(object): is_function = False # True for Function nodes # attributes below are set by the builder module or by raw factories lineno = None - fromlineno = None - tolineno = None col_offset = None # parent node in the tree parent = None @@ -408,6 +406,7 @@ class NodeNG(object): if self._explicit_inference is not None: # explicit_inference is not bound, give it self explicitly try: + # pylint: disable=not-callable return self._explicit_inference(self, context, **kwargs) except UseInferenceDefault: pass @@ -503,11 +502,12 @@ class NodeNG(object): if node_or_sequence is child: return [node_or_sequence] # /!\ compiler.ast Nodes have an __iter__ walking over child nodes - if isinstance(node_or_sequence, (tuple, list)) and child in node_or_sequence: + if (isinstance(node_or_sequence, (tuple, list)) + and child in node_or_sequence): return node_or_sequence - else: - msg = 'Could not find %s in %s\'s children' - raise AstroidError(msg % (repr(child), repr(self))) + + msg = 'Could not find %s in %s\'s children' + raise AstroidError(msg % (repr(child), repr(self))) def locate_child(self, child): """return a 2-uple (child attribute name, sequence or node)""" diff --git a/astroid/inference.py b/astroid/inference.py index 2280704..c1c0f0e 100644 --- a/astroid/inference.py +++ b/astroid/inference.py @@ -317,7 +317,7 @@ def infer_unaryop(self, context=None): yield operand except GeneratorExit: raise - except: + except Exception: # pylint: disable=broad-except yield YES nodes.UnaryOp._infer = path_wrapper(infer_unaryop) @@ -334,7 +334,7 @@ def _infer_binop(operator, operand1, operand2, context, failures=None): # will be the same operand1.getattr(BIN_OP_METHOD[operator]) yield operand1 - except: + except Exception: # pylint: disable=broad-except if failures is None: yield YES else: diff --git a/astroid/manager.py b/astroid/manager.py index b1fb305..e5cfe05 100644 --- a/astroid/manager.py +++ b/astroid/manager.py @@ -43,7 +43,7 @@ def astroid_wrapper(func, modname): return func(modname) except AstroidBuildingException as exc: print(exc) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-except import traceback traceback.print_exc() @@ -54,7 +54,7 @@ def _silent_no_wrap(func, modname): def safe_repr(obj): try: return repr(obj) - except: + except Exception: # pylint: disable=broad-except return '???' @@ -186,7 +186,7 @@ class AstroidManager(OptionsProviderMixIn): module = builder.string_build(importer.get_source(resource), zmodname, filepath) return module - except: + except Exception: # pylint: disable=broad-except continue return None diff --git a/astroid/modutils.py b/astroid/modutils.py index 5241f58..be8580a 100644 --- a/astroid/modutils.py +++ b/astroid/modutils.py @@ -562,7 +562,9 @@ def _search_zip(modpath, pic): if not importer.find_module(os.path.sep.join(modpath)): raise ImportError('No module named %s in %s/%s' % ( '.'.join(modpath[1:]), filepath, modpath)) - return PY_ZIPMODULE, os.path.abspath(filepath) + os.path.sep + os.path.sep.join(modpath), filepath + return (PY_ZIPMODULE, + os.path.abspath(filepath) + os.path.sep + os.path.sep.join(modpath), + filepath) raise ImportError('No module named %s' % '.'.join(modpath)) @@ -627,7 +629,7 @@ def _module_file(modpath, path=None): # Don't forget to close the stream to avoid # spurious ResourceWarnings. if stream: - stream.close() + stream.close() if checkeggs and mp_filename: fullabspath = [_cache_normalize_path(x) for x in _path] diff --git a/astroid/node_classes.py b/astroid/node_classes.py index 143dc17..cb768e8 100644 --- a/astroid/node_classes.py +++ b/astroid/node_classes.py @@ -93,7 +93,9 @@ def are_exclusive(stmt1, stmt2, exceptions=None): c2attr, c2node = node.locate_child(previous) c1attr, c1node = node.locate_child(children[node]) if c1node is not c2node: - if ((c2attr == 'body' and c1attr == 'handlers' and children[node].catch(exceptions)) or + if ((c2attr == 'body' + and c1attr == 'handlers' + and children[node].catch(exceptions)) or (c2attr == 'handlers' and c1attr == 'body' and previous.catch(exceptions)) or (c2attr == 'handlers' and c1attr == 'orelse') or (c2attr == 'orelse' and c1attr == 'handlers')): @@ -590,7 +592,7 @@ class Discard(Statement): value = None -class Ellipsis(NodeNG): +class Ellipsis(NodeNG): # pylint: disable=redefined-builtin """class representing an Ellipsis node""" diff --git a/astroid/nodes.py b/astroid/nodes.py index 67c2f8e..ff92962 100644 --- a/astroid/nodes.py +++ b/astroid/nodes.py @@ -34,20 +34,24 @@ on From and Import : """ -# pylint: disable=unused-import +# pylint: disable=unused-import,redefined-builtin __docformat__ = "restructuredtext en" -from astroid.node_classes import Arguments, AssAttr, Assert, Assign, \ - AssName, AugAssign, Backquote, BinOp, BoolOp, Break, CallFunc, Compare, \ - Comprehension, Const, Continue, Decorators, DelAttr, DelName, Delete, \ - Dict, Discard, Ellipsis, EmptyNode, ExceptHandler, Exec, ExtSlice, For, \ - From, Getattr, Global, If, IfExp, Import, Index, Keyword, \ - List, Name, Nonlocal, Pass, Print, Raise, Return, Set, Slice, Starred, Subscript, \ - TryExcept, TryFinally, Tuple, UnaryOp, While, With, Yield, YieldFrom, \ +from astroid.node_classes import ( + Arguments, AssAttr, Assert, Assign, + AssName, AugAssign, Backquote, BinOp, BoolOp, Break, CallFunc, Compare, + Comprehension, Const, Continue, Decorators, DelAttr, DelName, Delete, + Dict, Discard, Ellipsis, EmptyNode, ExceptHandler, Exec, ExtSlice, For, + From, Getattr, Global, If, IfExp, Import, Index, Keyword, + List, Name, Nonlocal, Pass, Print, Raise, Return, Set, Slice, Starred, Subscript, + TryExcept, TryFinally, Tuple, UnaryOp, While, With, Yield, YieldFrom, const_factory -from astroid.scoped_nodes import Module, GenExpr, Lambda, DictComp, \ - ListComp, SetComp, Function, Class +) +from astroid.scoped_nodes import ( + Module, GenExpr, Lambda, DictComp, + ListComp, SetComp, Function, Class, +) ALL_NODE_CLASSES = ( Arguments, AssAttr, Assert, Assign, AssName, AugAssign, @@ -71,4 +75,3 @@ ALL_NODE_CLASSES = ( While, With, Yield, YieldFrom ) - diff --git a/astroid/protocols.py b/astroid/protocols.py index dbe3239..a796c91 100644 --- a/astroid/protocols.py +++ b/astroid/protocols.py @@ -97,8 +97,8 @@ BIN_OP_IMPL = {'+': lambda a, b: a + b, '<<': lambda a, b: a << b, '>>': lambda a, b: a >> b, } -for key, impl in list(BIN_OP_IMPL.items()): - BIN_OP_IMPL[key+'='] = impl +for _KEY, _IMPL in list(BIN_OP_IMPL.items()): + BIN_OP_IMPL[_KEY + '='] = _IMPL def const_infer_binary_op(self, operator, other, context): for other in other.infer(context): @@ -108,7 +108,7 @@ def const_infer_binary_op(self, operator, other, context): try: yield const_factory(impl(self.value, other.value)) - except Exception: + except Exception: # pylint: disable=broad-except # ArithmeticError is not enough: float >> float is a TypeError # TODO : let pylint know about the problem pass diff --git a/astroid/raw_building.py b/astroid/raw_building.py index 392582c..008f120 100644 --- a/astroid/raw_building.py +++ b/astroid/raw_building.py @@ -54,6 +54,7 @@ def _attach_local_node(parent, node, name): _marker = object() + def attach_dummy_node(node, name, object=_marker): """create a dummy node and register it in the locals of the given node with the specified name @@ -192,7 +193,7 @@ def _base_class_object_build(node, member, basenames, name=None, localname=None) instdict = member().__dict__ else: raise TypeError - except: + except: # pylint: disable=bare-except pass else: for name, obj in instdict.items(): @@ -277,7 +278,7 @@ class InspectBuilder(object): elif isbuiltin(member): if (not _io_discrepancy(member) and self.imported_member(node, member, name)): - continue + continue object_build_methoddescriptor(node, member, name) elif isclass(member): if self.imported_member(node, member, name): @@ -298,7 +299,7 @@ class InspectBuilder(object): elif isdatadescriptor(member): assert isinstance(member, object) object_build_datadescriptor(node, member, name) - elif type(member) in _CONSTANTS: + elif isinstance(member, _CONSTANTS): attach_const_node(node, name, member) elif isroutine(member): # This should be called for Jython, where some builtin @@ -315,7 +316,7 @@ class InspectBuilder(object): # (see http://www.logilab.org/ticket/57299 for instance) try: modname = getattr(member, '__module__', None) - except: + except: # pylint: disable=bare-except # XXX use logging print('unexpected error while building astroid from living object') import traceback @@ -385,4 +386,3 @@ Const._proxied = property(_set_proxied) from types import GeneratorType Generator._proxied = Class(GeneratorType.__name__, GeneratorType.__doc__) Astroid_BUILDER.object_build(Generator._proxied, GeneratorType) - diff --git a/astroid/scoped_nodes.py b/astroid/scoped_nodes.py index b8140d3..87e881f 100644 --- a/astroid/scoped_nodes.py +++ b/astroid/scoped_nodes.py @@ -376,9 +376,6 @@ class Module(LocalsDictNodeNG): raise NotFoundError(name) except SyntaxError: raise NotFoundError(name) - except Exception:# XXX pylint tests never pass here; do we need it? - import traceback - traceback.print_exc() raise NotFoundError(name) getattr = remove_nodes(getattr, DelName) @@ -587,19 +584,19 @@ def _infer_decorator_callchain(node): if not node.parent: return try: - # TODO: We don't handle multiple inference results right now, - # because there's no flow to reason when the return - # is what we are looking for, a static or a class method. - result = next(node.infer_call_result(node.parent)) + # TODO: We don't handle multiple inference results right now, + # because there's no flow to reason when the return + # is what we are looking for, a static or a class method. + result = next(node.infer_call_result(node.parent)) except (StopIteration, InferenceError): - return + return if isinstance(result, Instance): - result = result._proxied + result = result._proxied if isinstance(result, Class): - if result.is_subtype_of('%s.classmethod' % BUILTINS): - return 'classmethod' - if result.is_subtype_of('%s.staticmethod' % BUILTINS): - return 'staticmethod' + if result.is_subtype_of('%s.classmethod' % BUILTINS): + return 'classmethod' + if result.is_subtype_of('%s.staticmethod' % BUILTINS): + return 'staticmethod' def _function_type(self): @@ -709,7 +706,6 @@ class Function(Statement, Lambda): special_attributes = set(('__name__', '__doc__', '__dict__')) is_function = True # attributes below are set by the builder module or by raw factories - blockstart_tolineno = None decorators = None _type = "function" type = cachedproperty(_function_type) @@ -951,7 +947,6 @@ class Class(Statement, LocalsDictNodeNG, FilterStmtsMixin): decorators = None special_attributes = set(('__name__', '__doc__', '__dict__', '__module__', '__bases__', '__mro__', '__subclasses__')) - blockstart_tolineno = None _type = None _metaclass_hack = False diff --git a/astroid/tests/unittest_builder.py b/astroid/tests/unittest_builder.py index 14ce5be..672e2c9 100644 --- a/astroid/tests/unittest_builder.py +++ b/astroid/tests/unittest_builder.py @@ -712,8 +712,13 @@ class ModuleBuildTest(resources.SysPathSetup, FileBuildTest): def setUp(self): super(ModuleBuildTest, self).setUp() abuilder = builder.AstroidBuilder() - import data.module - self.module = abuilder.module_build(data.module, 'data.module') + try: + import data.module + except ImportError: + # Make pylint happy. + self.skipTest('Unable to load data.module') + else: + self.module = abuilder.module_build(data.module, 'data.module') @unittest.skipIf(IS_PY3, "guess_encoding not used on Python 3") class TestGuessEncoding(unittest.TestCase): diff --git a/astroid/tests/unittest_inference.py b/astroid/tests/unittest_inference.py index 0e55d9a..2483df6 100644 --- a/astroid/tests/unittest_inference.py +++ b/astroid/tests/unittest_inference.py @@ -57,10 +57,10 @@ class InferenceUtilsTest(unittest.TestCase): def _assertInferElts(node_type, self, node, elts): - infered = next(node.infer()) - self.assertIsInstance(infered, node_type) - self.assertEqual(sorted(elt.value for elt in infered.elts), - elts) + infered = next(node.infer()) + self.assertIsInstance(infered, node_type) + self.assertEqual(sorted(elt.value for elt in infered.elts), + elts) def partialmethod(func, arg): """similar to functools.partial but return a lambda instead of a class so returned value may be @@ -478,7 +478,6 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): infered = next(n.infer()) self.assertEqual(infered.getitem(0).value, '_') - def test_builtin_types(self): code = 's = {1}' ast = test_utils.build_module(code, __name__) n = ast['s'] @@ -1420,149 +1419,149 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): [base.name for base in klass.ancestors()]) def test_stop_iteration_leak(self): - code = """ - class Test: - def __init__(self): - self.config = {0: self.config[0]} - self.config[0].test() #@ - """ - ast = test_utils.extract_node(code, __name__) - expr = ast.func.expr - self.assertRaises(InferenceError, next, expr.infer()) + code = """ + class Test: + def __init__(self): + self.config = {0: self.config[0]} + self.config[0].test() #@ + """ + ast = test_utils.extract_node(code, __name__) + expr = ast.func.expr + self.assertRaises(InferenceError, next, expr.infer()) def test_tuple_builtin_inference(self): - code = """ - var = (1, 2) - tuple() #@ - tuple([1]) #@ - tuple({2}) #@ - tuple("abc") #@ - tuple({1: 2}) #@ - tuple(var) #@ - tuple(tuple([1])) #@ - - tuple(None) #@ - tuple(1) #@ - tuple(1, 2) #@ - """ - ast = test_utils.extract_node(code, __name__) - - self.assertInferTuple(ast[0], []) - self.assertInferTuple(ast[1], [1]) - self.assertInferTuple(ast[2], [2]) - self.assertInferTuple(ast[3], ["a", "b", "c"]) - self.assertInferTuple(ast[4], [1]) - self.assertInferTuple(ast[5], [1, 2]) - self.assertInferTuple(ast[6], [1]) - - for node in ast[7:]: - infered = next(node.infer()) - self.assertIsInstance(infered, Instance) - self.assertEqual(infered.qname(), "{}.tuple".format(BUILTINS)) + code = """ + var = (1, 2) + tuple() #@ + tuple([1]) #@ + tuple({2}) #@ + tuple("abc") #@ + tuple({1: 2}) #@ + tuple(var) #@ + tuple(tuple([1])) #@ + + tuple(None) #@ + tuple(1) #@ + tuple(1, 2) #@ + """ + ast = test_utils.extract_node(code, __name__) + + self.assertInferTuple(ast[0], []) + self.assertInferTuple(ast[1], [1]) + self.assertInferTuple(ast[2], [2]) + self.assertInferTuple(ast[3], ["a", "b", "c"]) + self.assertInferTuple(ast[4], [1]) + self.assertInferTuple(ast[5], [1, 2]) + self.assertInferTuple(ast[6], [1]) + + for node in ast[7:]: + infered = next(node.infer()) + self.assertIsInstance(infered, Instance) + self.assertEqual(infered.qname(), "{}.tuple".format(BUILTINS)) def test_frozenset_builtin_inference(self): - code = """ - var = (1, 2) - frozenset() #@ - frozenset([1, 2, 1]) #@ - frozenset({2, 3, 1}) #@ - frozenset("abcab") #@ - frozenset({1: 2}) #@ - frozenset(var) #@ - frozenset(tuple([1])) #@ - - frozenset(set(tuple([4, 5, set([2])]))) #@ - frozenset(None) #@ - frozenset(1) #@ - frozenset(1, 2) #@ - """ - ast = test_utils.extract_node(code, __name__) - - self.assertInferFrozenSet(ast[0], []) - self.assertInferFrozenSet(ast[1], [1, 2]) - self.assertInferFrozenSet(ast[2], [1, 2, 3]) - self.assertInferFrozenSet(ast[3], ["a", "b", "c"]) - self.assertInferFrozenSet(ast[4], [1]) - self.assertInferFrozenSet(ast[5], [1, 2]) - self.assertInferFrozenSet(ast[6], [1]) - - for node in ast[7:]: - infered = next(node.infer()) - self.assertIsInstance(infered, Instance) - self.assertEqual(infered.qname(), "{}.frozenset".format(BUILTINS)) + code = """ + var = (1, 2) + frozenset() #@ + frozenset([1, 2, 1]) #@ + frozenset({2, 3, 1}) #@ + frozenset("abcab") #@ + frozenset({1: 2}) #@ + frozenset(var) #@ + frozenset(tuple([1])) #@ + + frozenset(set(tuple([4, 5, set([2])]))) #@ + frozenset(None) #@ + frozenset(1) #@ + frozenset(1, 2) #@ + """ + ast = test_utils.extract_node(code, __name__) + + self.assertInferFrozenSet(ast[0], []) + self.assertInferFrozenSet(ast[1], [1, 2]) + self.assertInferFrozenSet(ast[2], [1, 2, 3]) + self.assertInferFrozenSet(ast[3], ["a", "b", "c"]) + self.assertInferFrozenSet(ast[4], [1]) + self.assertInferFrozenSet(ast[5], [1, 2]) + self.assertInferFrozenSet(ast[6], [1]) + + for node in ast[7:]: + infered = next(node.infer()) + self.assertIsInstance(infered, Instance) + self.assertEqual(infered.qname(), "{}.frozenset".format(BUILTINS)) def test_set_builtin_inference(self): - code = """ - var = (1, 2) - set() #@ - set([1, 2, 1]) #@ - set({2, 3, 1}) #@ - set("abcab") #@ - set({1: 2}) #@ - set(var) #@ - set(tuple([1])) #@ - - set(set(tuple([4, 5, set([2])]))) #@ - set(None) #@ - set(1) #@ - set(1, 2) #@ - """ - ast = test_utils.extract_node(code, __name__) - - self.assertInferSet(ast[0], []) - self.assertInferSet(ast[1], [1, 2]) - self.assertInferSet(ast[2], [1, 2, 3]) - self.assertInferSet(ast[3], ["a", "b", "c"]) - self.assertInferSet(ast[4], [1]) - self.assertInferSet(ast[5], [1, 2]) - self.assertInferSet(ast[6], [1]) - - for node in ast[7:]: - infered = next(node.infer()) - self.assertIsInstance(infered, Instance) - self.assertEqual(infered.qname(), "{}.set".format(BUILTINS)) + code = """ + var = (1, 2) + set() #@ + set([1, 2, 1]) #@ + set({2, 3, 1}) #@ + set("abcab") #@ + set({1: 2}) #@ + set(var) #@ + set(tuple([1])) #@ + + set(set(tuple([4, 5, set([2])]))) #@ + set(None) #@ + set(1) #@ + set(1, 2) #@ + """ + ast = test_utils.extract_node(code, __name__) + + self.assertInferSet(ast[0], []) + self.assertInferSet(ast[1], [1, 2]) + self.assertInferSet(ast[2], [1, 2, 3]) + self.assertInferSet(ast[3], ["a", "b", "c"]) + self.assertInferSet(ast[4], [1]) + self.assertInferSet(ast[5], [1, 2]) + self.assertInferSet(ast[6], [1]) + + for node in ast[7:]: + infered = next(node.infer()) + self.assertIsInstance(infered, Instance) + self.assertEqual(infered.qname(), "{}.set".format(BUILTINS)) def test_list_builtin_inference(self): - code = """ - var = (1, 2) - list() #@ - list([1, 2, 1]) #@ - list({2, 3, 1}) #@ - list("abcab") #@ - list({1: 2}) #@ - list(var) #@ - list(tuple([1])) #@ - - list(list(tuple([4, 5, list([2])]))) #@ - list(None) #@ - list(1) #@ - list(1, 2) #@ - """ - ast = test_utils.extract_node(code, __name__) - self.assertInferList(ast[0], []) - self.assertInferList(ast[1], [1, 1, 2]) - self.assertInferList(ast[2], [1, 2, 3]) - self.assertInferList(ast[3], ["a", "a", "b", "b", "c"]) - self.assertInferList(ast[4], [1]) - self.assertInferList(ast[5], [1, 2]) - self.assertInferList(ast[6], [1]) - - for node in ast[7:]: - infered = next(node.infer()) - self.assertIsInstance(infered, Instance) - self.assertEqual(infered.qname(), "{}.list".format(BUILTINS)) + code = """ + var = (1, 2) + list() #@ + list([1, 2, 1]) #@ + list({2, 3, 1}) #@ + list("abcab") #@ + list({1: 2}) #@ + list(var) #@ + list(tuple([1])) #@ + + list(list(tuple([4, 5, list([2])]))) #@ + list(None) #@ + list(1) #@ + list(1, 2) #@ + """ + ast = test_utils.extract_node(code, __name__) + self.assertInferList(ast[0], []) + self.assertInferList(ast[1], [1, 1, 2]) + self.assertInferList(ast[2], [1, 2, 3]) + self.assertInferList(ast[3], ["a", "a", "b", "b", "c"]) + self.assertInferList(ast[4], [1]) + self.assertInferList(ast[5], [1, 2]) + self.assertInferList(ast[6], [1]) + + for node in ast[7:]: + infered = next(node.infer()) + self.assertIsInstance(infered, Instance) + self.assertEqual(infered.qname(), "{}.list".format(BUILTINS)) @test_utils.require_version('3.0') def test_builtin_inference_py3k(self): - code = """ - list(b"abc") #@ - tuple(b"abc") #@ - set(b"abc") #@ - """ - ast = test_utils.extract_node(code, __name__) - self.assertInferList(ast[0], [97, 98, 99]) - self.assertInferTuple(ast[1], [97, 98, 99]) - self.assertInferSet(ast[2], [97, 98, 99]) + code = """ + list(b"abc") #@ + tuple(b"abc") #@ + set(b"abc") #@ + """ + ast = test_utils.extract_node(code, __name__) + self.assertInferList(ast[0], [97, 98, 99]) + self.assertInferTuple(ast[1], [97, 98, 99]) + self.assertInferSet(ast[2], [97, 98, 99]) def test_dict_inference(self): code = """ @@ -1610,66 +1609,66 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): def test_str_methods(self): - code = """ - ' '.decode() #@ - - ' '.encode() #@ - ' '.join('abcd') #@ - ' '.replace('a', 'b') #@ - ' '.format('a') #@ - ' '.capitalize() #@ - ' '.title() #@ - ' '.lower() #@ - ' '.upper() #@ - ' '.swapcase() #@ - ' '.strip() #@ - ' '.rstrip() #@ - ' '.lstrip() #@ - ' '.rjust() #@ - ' '.ljust() #@ - ' '.center() #@ - - ' '.index() #@ - ' '.find() #@ - ' '.count() #@ - """ - ast = test_utils.extract_node(code, __name__) - self.assertInferConst(ast[0], u'') - for i in range(1, 16): - self.assertInferConst(ast[i], '') - for i in range(16, 19): - self.assertInferConst(ast[i], 0) + code = """ + ' '.decode() #@ + + ' '.encode() #@ + ' '.join('abcd') #@ + ' '.replace('a', 'b') #@ + ' '.format('a') #@ + ' '.capitalize() #@ + ' '.title() #@ + ' '.lower() #@ + ' '.upper() #@ + ' '.swapcase() #@ + ' '.strip() #@ + ' '.rstrip() #@ + ' '.lstrip() #@ + ' '.rjust() #@ + ' '.ljust() #@ + ' '.center() #@ + + ' '.index() #@ + ' '.find() #@ + ' '.count() #@ + """ + ast = test_utils.extract_node(code, __name__) + self.assertInferConst(ast[0], u'') + for i in range(1, 16): + self.assertInferConst(ast[i], '') + for i in range(16, 19): + self.assertInferConst(ast[i], 0) def test_unicode_methods(self): - code = """ - u' '.encode() #@ - - u' '.decode() #@ - u' '.join('abcd') #@ - u' '.replace('a', 'b') #@ - u' '.format('a') #@ - u' '.capitalize() #@ - u' '.title() #@ - u' '.lower() #@ - u' '.upper() #@ - u' '.swapcase() #@ - u' '.strip() #@ - u' '.rstrip() #@ - u' '.lstrip() #@ - u' '.rjust() #@ - u' '.ljust() #@ - u' '.center() #@ - - u' '.index() #@ - u' '.find() #@ - u' '.count() #@ - """ - ast = test_utils.extract_node(code, __name__) - self.assertInferConst(ast[0], '') - for i in range(1, 16): - self.assertInferConst(ast[i], u'') - for i in range(16, 19): - self.assertInferConst(ast[i], 0) + code = """ + u' '.encode() #@ + + u' '.decode() #@ + u' '.join('abcd') #@ + u' '.replace('a', 'b') #@ + u' '.format('a') #@ + u' '.capitalize() #@ + u' '.title() #@ + u' '.lower() #@ + u' '.upper() #@ + u' '.swapcase() #@ + u' '.strip() #@ + u' '.rstrip() #@ + u' '.lstrip() #@ + u' '.rjust() #@ + u' '.ljust() #@ + u' '.center() #@ + + u' '.index() #@ + u' '.find() #@ + u' '.count() #@ + """ + ast = test_utils.extract_node(code, __name__) + self.assertInferConst(ast[0], '') + for i in range(1, 16): + self.assertInferConst(ast[i], u'') + for i in range(16, 19): + self.assertInferConst(ast[i], 0) def test_scope_lookup_same_attributes(self): code = ''' diff --git a/astroid/tests/unittest_manager.py b/astroid/tests/unittest_manager.py index 07b2588..e14e3ea 100644 --- a/astroid/tests/unittest_manager.py +++ b/astroid/tests/unittest_manager.py @@ -52,16 +52,12 @@ class AstroidManagerTest(resources.SysPathSetup, self.manager.clear_cache(self._builtins) # take care of borg def test_ast_from_file(self): - """check if the method return a good astroid object""" - import unittest filepath = unittest.__file__ astroid = self.manager.ast_from_file(filepath) self.assertEqual(astroid.name, 'unittest') self.assertIn('unittest', self.manager.astroid_cache) def test_ast_from_file_cache(self): - """check if the cache works""" - import unittest filepath = unittest.__file__ self.manager.ast_from_file(filepath) astroid = self.manager.ast_from_file('unhandledName', 'unittest') @@ -69,15 +65,12 @@ class AstroidManagerTest(resources.SysPathSetup, self.assertIn('unittest', self.manager.astroid_cache) def test_ast_from_file_astro_builder(self): - """check if the source is at True, AstroidBuilder build a good astroid""" - import unittest filepath = unittest.__file__ astroid = self.manager.ast_from_file(filepath, None, True, True) self.assertEqual(astroid.name, 'unittest') self.assertIn('unittest', self.manager.astroid_cache) def test_ast_from_file_name_astro_builder_exception(self): - """check if an exception is thrown if we give a wrong filepath""" self.assertRaises(AstroidBuildingException, self.manager.ast_from_file, 'unhandledName') def test_do_not_expose_main(self): @@ -86,20 +79,17 @@ class AstroidManagerTest(resources.SysPathSetup, self.assertEqual(obj.items(), []) def test_ast_from_module_name(self): - """check if the ast_from_module_name method return a good astroid""" astroid = self.manager.ast_from_module_name('unittest') self.assertEqual(astroid.name, 'unittest') self.assertIn('unittest', self.manager.astroid_cache) def test_ast_from_module_name_not_python_source(self): - """check if the ast_from_module_name method return a good astroid with a no python source module""" astroid = self.manager.ast_from_module_name('time') self.assertEqual(astroid.name, 'time') self.assertIn('time', self.manager.astroid_cache) self.assertEqual(astroid.pure_python, False) def test_ast_from_module_name_astro_builder_exception(self): - """check if the method raise an exception if we give a wrong module""" self.assertRaises(AstroidBuildingException, self.manager.ast_from_module_name, 'unhandledModule') def _test_ast_from_zip(self, archive): diff --git a/astroid/tests/unittest_modutils.py b/astroid/tests/unittest_modutils.py index 51d4318..95cb1f7 100644 --- a/astroid/tests/unittest_modutils.py +++ b/astroid/tests/unittest_modutils.py @@ -186,6 +186,7 @@ class StandardLibModuleTest(resources.SysPathSetup, unittest.TestCase): def test_builtin(self): self.assertEqual(modutils.is_standard_module('sys'), True) + self.assertEqual(modutils.is_standard_module('marshal'), True) def test_nonstandard(self): self.assertEqual(modutils.is_standard_module('logilab'), False) @@ -193,9 +194,6 @@ class StandardLibModuleTest(resources.SysPathSetup, unittest.TestCase): def test_unknown(self): self.assertEqual(modutils.is_standard_module('unknown'), False) - def test_builtin(self): - self.assertEqual(modutils.is_standard_module('marshal'), True) - def test_4(self): self.assertEqual(modutils.is_standard_module('hashlib'), True) self.assertEqual(modutils.is_standard_module('pickle'), True) diff --git a/astroid/tests/unittest_nodes.py b/astroid/tests/unittest_nodes.py index 954efb3..3e53750 100644 --- a/astroid/tests/unittest_nodes.py +++ b/astroid/tests/unittest_nodes.py @@ -30,7 +30,7 @@ from astroid import builder from astroid import nodes from astroid import test_utils from astroid.tests import resources -from astroid import test_utils + abuilder = builder.AstroidBuilder() diff --git a/astroid/tests/unittest_raw_building.py b/astroid/tests/unittest_raw_building.py index 0124ed1..f268032 100644 --- a/astroid/tests/unittest_raw_building.py +++ b/astroid/tests/unittest_raw_building.py @@ -18,7 +18,7 @@ class RawBuildingTC(unittest.TestCase): def test_attach_dummy_node(self): node = build_module('MyModule') - dummy = attach_dummy_node(node, 'DummyNode') + attach_dummy_node(node, 'DummyNode') self.assertEqual(1, len(list(node.get_children()))) def test_build_module(self): diff --git a/astroid/tests/unittest_regrtest.py b/astroid/tests/unittest_regrtest.py index 7db372c..09c580e 100644 --- a/astroid/tests/unittest_regrtest.py +++ b/astroid/tests/unittest_regrtest.py @@ -187,7 +187,7 @@ def run(): classes = astroid.nodes_of_class(nodes.Class) for klass in classes: # triggers the _is_metaclass call - klass.type + klass.type # pylint: disable=pointless-statement def test_decorator_callchain_issue42(self): builder = AstroidBuilder() diff --git a/astroid/tests/unittest_scoped_nodes.py b/astroid/tests/unittest_scoped_nodes.py index e61f427..f35c7de 100644 --- a/astroid/tests/unittest_scoped_nodes.py +++ b/astroid/tests/unittest_scoped_nodes.py @@ -205,6 +205,7 @@ class ModuleNodeTest(ModuleLoader, unittest.TestCase): if __pkginfo__.numversion >= (1, 6): # file_stream is slated for removal in astroid 1.6. with self.assertRaises(AttributeError): + # pylint: disable=pointless-statement astroid.file_stream else: # Until astroid 1.6, Module.file_stream will emit @@ -91,8 +91,12 @@ confidence= # --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
-disable=all
-enable=trailing-whitespace, bad-whitespace, unused-import, unused-variable,bad-continuation
+disable=invalid-name,protected-access,no-self-use,unused-argument,
+ no-member,line-too-long,too-many-branches,too-few-public-methods,
+ too-many-public-methods,too-many-instance-attributes,
+ super-init-not-called,redefined-builtin,cyclic-import,
+ too-many-return-statements,redefined-outer-name,undefined-variable,
+ too-many-locals,method-hidden,duplicate-code,attribute-defined-outside-init
[BASIC]
|