diff options
Diffstat (limited to 'pylint/test/input')
183 files changed, 6212 insertions, 0 deletions
diff --git a/pylint/test/input/__init__.py b/pylint/test/input/__init__.py new file mode 100644 index 0000000..60e92b7 --- /dev/null +++ b/pylint/test/input/__init__.py @@ -0,0 +1 @@ +"""test""" diff --git a/pylint/test/input/func_3k_removed_stuff_py_30.py b/pylint/test/input/func_3k_removed_stuff_py_30.py new file mode 100644 index 0000000..75f7eb8 --- /dev/null +++ b/pylint/test/input/func_3k_removed_stuff_py_30.py @@ -0,0 +1,13 @@ +"""test relative import""" +# pylint: disable=no-absolute-import +__revision__ = filter(None, map(str, (1, 2, 3))) +from __future__ import generators, print_function + +import func_w0302 + +def function(): + """something""" + print(func_w0302) + unic = u"unicode" + low = unic.looower + return low diff --git a/pylint/test/input/func_assert_2uple.py b/pylint/test/input/func_assert_2uple.py new file mode 100644 index 0000000..de93d3b --- /dev/null +++ b/pylint/test/input/func_assert_2uple.py @@ -0,0 +1,11 @@ +'''Assert check example''' +__revision__ = 0 + +assert (1 == 1, 2 == 2), "no error" +assert (1 == 1, 2 == 2) #this should generate a warning +assert 1 == 1, "no error" +assert (1 == 1, ), "no error" +assert (1 == 1, ) +assert (1 == 1, 2 == 2, 3 == 5), "no error" +assert () +assert (True, 'error msg') #this should generate a warning diff --git a/pylint/test/input/func_attrs_definition_order.py b/pylint/test/input/func_attrs_definition_order.py new file mode 100644 index 0000000..896426d --- /dev/null +++ b/pylint/test/input/func_attrs_definition_order.py @@ -0,0 +1,33 @@ +# pylint: disable=R0903, print-statement +"""yo""" + +__revision__ = '$I$' + +class Aaaa(object): + """class with attributes defined in wrong order""" + def __init__(self): + var1 = self._var2 + self._var2 = 3 + print var1 + +class Bbbb(object): + """hop""" + __revision__ = __revision__ # no problemo marge + + def __getattr__(self, attr): + # pylint: disable=W0201 + try: + return self.__repo + except AttributeError: + self.__repo = attr + return attr + + + def catchme(self, attr): + """no AttributeError catched""" + # pylint: disable=W0201 + try: + return self._repo + except ValueError: + self._repo = attr + return attr diff --git a/pylint/test/input/func_bad_assigment_to_exception_var.py b/pylint/test/input/func_bad_assigment_to_exception_var.py new file mode 100644 index 0000000..b147446 --- /dev/null +++ b/pylint/test/input/func_bad_assigment_to_exception_var.py @@ -0,0 +1,30 @@ +# pylint:disable=C0103, print-statement, no-absolute-import +"""ho ho ho""" +__revision__ = 'toto' + +import sys + +e = 1 +e2 = 'yo' +e3 = None +try: + raise e +except Exception, ex: + print ex + _, _, tb = sys.exc_info() + + + +def func(): + """bla bla bla""" + raise e3 + +def reraise(): + """reraise a catched exception instance""" + try: + raise Exception() + except Exception, exc: + print exc + raise exc + +raise e3 diff --git a/pylint/test/input/func_bad_cont_dictcomp_py27.py b/pylint/test/input/func_bad_cont_dictcomp_py27.py new file mode 100644 index 0000000..a552710 --- /dev/null +++ b/pylint/test/input/func_bad_cont_dictcomp_py27.py @@ -0,0 +1,38 @@ +"""Bad continuations in dictionary comprehensions.""" + +__revision__ = 0 + +# Dictionary comprehensions should not require extra indentation when breaking +# before the 'for', which is not part of the value +C1 = {'key{}'.format(x): 'value{}'.format(x) + for x in range(3)} + +C2 = {'key{}'.format(x): 'value{}'.format(x) for x in + range(3)} + +# Dictionary comprehensions with multiple loops broken in different places +C3 = {x*y: (x, y) for x in range(3) for y in range(3)} + +C4 = {x*y: (x, y) + for x in range(3) for y in range(3)} + +C5 = {x*y: (x, y) for x + in range(3) for y in range(3)} + +C6 = {x*y: (x, y) for x in range(3) + for y in range(3)} + +C7 = {key: + key ** 2 + for key in range(10)} + +C8 = { + key: key ** 2 + for key in range(10)} + +# Misaligned cases for dict comprehensions +C9 = {'key{}'.format(x): 'value{}'.format(x) + for x in range(3)} # [bad-continuation] + +C9 = {'key{}'.format(x): 'value{}'.format(x) + for x in range(3)} # [bad-continuation] diff --git a/pylint/test/input/func_bad_exception_context_py30.py b/pylint/test/input/func_bad_exception_context_py30.py new file mode 100644 index 0000000..98b44ee --- /dev/null +++ b/pylint/test/input/func_bad_exception_context_py30.py @@ -0,0 +1,24 @@ +"""Check that raise ... from .. uses a proper exception context """ + +# pylint: disable=unreachable, import-error + +import socket, unknown + +__revision__ = 0 + +class ExceptionSubclass(Exception): + """ subclass """ + +def test(): + """ docstring """ + raise IndexError from 1 + raise IndexError from None + raise IndexError from ZeroDivisionError + raise IndexError from object() + raise IndexError from ExceptionSubclass + raise IndexError from socket.error + raise IndexError() from None + raise IndexError() from ZeroDivisionError + raise IndexError() from ZeroDivisionError() + raise IndexError() from object() + raise IndexError() from unknown diff --git a/pylint/test/input/func_base_useless_pass.py b/pylint/test/input/func_base_useless_pass.py new file mode 100644 index 0000000..9faae59 --- /dev/null +++ b/pylint/test/input/func_base_useless_pass.py @@ -0,0 +1,9 @@ +"""W0107: unnecessary pass statement +""" +__revision__ = None + +try: + A = 2 +except ValueError: + print A # pylint: disable=print-statement + pass diff --git a/pylint/test/input/func_block_disable_msg.py b/pylint/test/input/func_block_disable_msg.py new file mode 100644 index 0000000..927b218 --- /dev/null +++ b/pylint/test/input/func_block_disable_msg.py @@ -0,0 +1,1026 @@ +# pylint: disable=C0302,bare-except,print-statement +"""pylint option block-disable""" +__revision__ = None + +class Foo(object): + """block-disable test""" + + def __init__(self): + pass + + def meth1(self, arg): + """this issues a message""" + print self + + def meth2(self, arg): + """and this one not""" + # pylint: disable=W0613 + print self\ + + "foo" + + def meth3(self): + """test one line disabling""" + # no error + print self.bla # pylint: disable=E1101 + # error + print self.blop + + def meth4(self): + """test re-enabling""" + # pylint: disable=E1101 + # no error + print self.bla + print self.blop + # pylint: enable=E1101 + # error + print self.blip + + def meth5(self): + """test IF sub-block re-enabling""" + # pylint: disable=E1101 + # no error + print self.bla + if self.blop: + # pylint: enable=E1101 + # error + print self.blip + else: + # no error + print self.blip + # no error + print self.blip + + def meth6(self): + """test TRY/EXCEPT sub-block re-enabling""" + # pylint: disable=E1101 + # no error + print self.bla + try: + # pylint: enable=E1101 + # error + print self.blip + except UndefinedName: # pylint: disable=E0602 + # no error + print self.blip + # no error + print self.blip + + def meth7(self): + """test one line block opening disabling""" + if self.blop: # pylint: disable=E1101 + # error + print self.blip + else: + # error + print self.blip + # error + print self.blip + + + def meth8(self): + """test late disabling""" + # error + print self.blip + # pylint: disable=E1101 + # no error + print self.bla + print self.blop + + def meth9(self): + """test re-enabling right after a block with whitespace""" + eris = 5 + + if eris: + print "In block" + + # pylint: disable=E1101 + # no error + print self.bla + print self.blu + # pylint: enable=E1101 + # error + print self.blip + + def meth10(self): + """Test double disable""" + # pylint: disable=E1101 + # no error + print self.bla + # pylint: disable=E1101 + print self.blu + + +class ClassLevelMessage(object): + """shouldn't display to much attributes/not enough methods messages + """ + # pylint: disable=R0902,R0903 + + def __init__(self): + self.attr1 = 1 + self.attr2 = 1 + self.attr3 = 1 + self.attr4 = 1 + self.attr5 = 1 + self.attr6 = 1 + self.attr7 = 1 + self.attr8 = 1 + self.attr9 = 1 + self.attr0 = 1 + + def too_complex_but_thats_ok(self, attr1, attr2): + """THIS Method has too much branches and returns but i don't care + """ + # pylint: disable=R0912,R0911 + try: + attr3 = attr1+attr2 + except ValueError: + attr3 = None + except: + return 'duh', self + if attr1: + for i in attr1: + if attr2: + return i + else: + return 'duh' + elif attr2: + for i in attr2: + if attr2: + return i + else: + return 'duh' + else: + for i in range(15): + if attr3: + return i + else: + return 'doh' + return None + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +print 'hop, too many lines but i don\'t care' diff --git a/pylint/test/input/func_break_or_return_in_try_finally.py b/pylint/test/input/func_break_or_return_in_try_finally.py new file mode 100644 index 0000000..d9a50f9 --- /dev/null +++ b/pylint/test/input/func_break_or_return_in_try_finally.py @@ -0,0 +1,44 @@ +'Exeptions may be silently swallowed' +from __future__ import print_function +__revision__ = None + +def insidious_break_and_return(): + """I found you !""" + for i in range(0, -5, -1): + my_var = 0 + print(i) + try: + my_var += 1.0/i + if i < -3: + break # :D + else: + return my_var # :D + finally: + if i > -2: + break # :( + else: + return my_var # :( + return None + +def break_and_return(): + """I found you !""" + for i in range(0, -5, -1): + my_var = 0 + if i: + break # :D + try: + my_var += 1.0/i + finally: + for i in range(2): + if True: + break # :D + else: + def strange(): + """why not ?""" + if True: + return my_var # :D + strange() + if i: + break # :D + else: + return # :D diff --git a/pylint/test/input/func_bug113231.py b/pylint/test/input/func_bug113231.py new file mode 100644 index 0000000..80996c3 --- /dev/null +++ b/pylint/test/input/func_bug113231.py @@ -0,0 +1,24 @@ +# pylint: disable=E1101 +# pylint: disable=C0103 +# pylint: disable=R0903 +"""test bugfix for #113231 in logging checker +""" +from __future__ import absolute_import +__revision__ = '' + +# Muck up the names in an effort to confuse... +import logging as renamed_logging + +class Logger(object): + """Fake logger""" + pass + +logger = renamed_logging.getLogger(__name__) +fake_logger = Logger() + +# Statements that should be flagged: +renamed_logging.warn('%s, %s' % (4, 5)) +logger.warn('%s' % 5) + +# Statements that should not be flagged: +fake_logger.warn('%s' % 5) diff --git a/pylint/test/input/func_continue_not_in_loop.py b/pylint/test/input/func_continue_not_in_loop.py new file mode 100644 index 0000000..4186aa5 --- /dev/null +++ b/pylint/test/input/func_continue_not_in_loop.py @@ -0,0 +1,14 @@ +"""this module produces a SyntaxError at execution time""" + +__revision__ = None + +def run(): + """simple function""" + if True: + continue + else: + break + +if __name__ == '__main__': + run() + diff --git a/pylint/test/input/func_dangerous_default.py b/pylint/test/input/func_dangerous_default.py new file mode 100644 index 0000000..dcf7380 --- /dev/null +++ b/pylint/test/input/func_dangerous_default.py @@ -0,0 +1,76 @@ +"""docstring""" +# pylint: disable=print-statement +__revision__ = '' + +HEHE = {} + +def function1(value=[]): + """docstring""" + print value + +def function2(value=HEHE): + """docstring""" + print value + +def function3(value): + """docstring""" + print value + +def function4(value=set()): + """set is mutable and dangerous.""" + print value + +def function5(value=frozenset()): + """frozenset is immutable and safe.""" + print value + +GLOBAL_SET = set() + +def function6(value=GLOBAL_SET): + """set is mutable and dangerous.""" + print value + +def function7(value=dict()): + """dict is mutable and dangerous.""" + print value + +def function8(value=list()): + """list is mutable and dangerous.""" + print value + +def function9(value=[1, 2, 3, 4]): + """list with items should not output item values in error message""" + print value + +def function10(value={'a': 1, 'b': 2}): + """dictionaries with items should not output item values in error message""" + print value + +def function11(value=list([1, 2, 3])): + """list with items should not output item values in error message""" + print value + +def function12(value=dict([('a', 1), ('b', 2)])): + """dictionaries with items should not output item values in error message""" + print value + +OINK = { + 'a': 1, + 'b': 2 +} + +def function13(value=OINK): + """dictionaries with items should not output item values in error message""" + print value + +def function14(value=dict([(1, 2), (1, 2, 3)])): + """a dictionary which will not be inferred to a syntax AST, but to an + astroid.Instance. + """ + return value + +INVALID_DICT = dict([(1, 2), (1, 2, 3)]) + +def function15(value=INVALID_DICT): + """The same situation as function14.""" + return value diff --git a/pylint/test/input/func_defining-attr-methods_order.py b/pylint/test/input/func_defining-attr-methods_order.py new file mode 100644 index 0000000..28918f2 --- /dev/null +++ b/pylint/test/input/func_defining-attr-methods_order.py @@ -0,0 +1,73 @@ +# pylint: disable=C0103, too-few-public-methods + +''' Test that y is defined properly, z is not. + Default defining methods are __init__, + __new__, and setUp. + Order of methods should not matter. ''' + +__revision__ = '' + +class A(object): + ''' class A ''' + + def __init__(self): + ''' __init__ docstring filler ''' + self.x = 0 + self.setUp() + + def set_y(self, y): + ''' set_y docstring filler ''' + self.y = y + + def set_x(self, x): + ''' set_x docstring filler ''' + self.x = x + + def set_z(self, z): + ''' set_z docstring filler ''' + self.z = z + self.z = z + + def setUp(self): + ''' setUp docstring filler ''' + self.x = 0 + self.y = 0 + +class B(A): + ''' class B ''' + + def test(self): + """ test """ + self.z = 44 + +class C(object): + ''' class C ''' + + def __init__(self): + self._init() + + def _init(self): + ''' called by __init__ ''' + self.z = 44 + +class D(object): + ''' class D ''' + + def setUp(self): + ''' defining method ''' + self.set_z() + + def set_z(self): + ''' called by the parent. ''' + self.z = 42 + +class E(object): + ''' Reassign the function. ''' + + def __init__(self): + i = self._init + i() + + def _init(self): + ''' called by __init__ ''' + self.z = 44 diff --git a/pylint/test/input/func_deprecated_lambda_py_30.py b/pylint/test/input/func_deprecated_lambda_py_30.py new file mode 100644 index 0000000..74b3241 --- /dev/null +++ b/pylint/test/input/func_deprecated_lambda_py_30.py @@ -0,0 +1,24 @@ +# pylint: disable=missing-docstring,bad-builtin,invalid-name,no-absolute-import +__revision__ = "$Id$" + +import functools + +# Don't do this, use a comprehension instead. +assert map(lambda x: x*2, [1, 2, 3]) == [2, 4, 6] + +assert filter(lambda x: x != 1, [1, 2, 3]) == [2, 3] + +# It's still ok to use map and filter with anything but an inline lambda. +double = lambda x: x * 2 +assert map(double, [1, 2, 3]) == [2, 4, 6] + +# It's also ok to pass lambdas to other functions. +assert functools.reduce(lambda x, y: x * y, [1, 2, 3, 4]) == 24 + +# Or to a undefined function or one with varargs +def f(*a): + return len(a) + +f(lambda x, y: x + y, [1, 2, 3]) + +undefined_function(lambda: 2) # pylint: disable=undefined-variable diff --git a/pylint/test/input/func_deprecated_module_py30.py b/pylint/test/input/func_deprecated_module_py30.py new file mode 100644 index 0000000..cadbac6 --- /dev/null +++ b/pylint/test/input/func_deprecated_module_py30.py @@ -0,0 +1,12 @@ +"""test deprecated module +""" + +__revision__ = 0 + + +if __revision__: + import optparse + print optparse + # false positive (#10061) + import stringfile + print stringfile diff --git a/pylint/test/input/func_deprecated_module_py_30.py b/pylint/test/input/func_deprecated_module_py_30.py new file mode 100644 index 0000000..7d2c19f --- /dev/null +++ b/pylint/test/input/func_deprecated_module_py_30.py @@ -0,0 +1,12 @@ +"""test deprecated module +""" +from __future__ import absolute_import, print_function +__revision__ = 0 + + +if __revision__: + import Bastion + print(Bastion) + # false positive (#10061) + import stringfile + print(stringfile) diff --git a/pylint/test/input/func_disable_linebased.py b/pylint/test/input/func_disable_linebased.py new file mode 100644 index 0000000..953848b --- /dev/null +++ b/pylint/test/input/func_disable_linebased.py @@ -0,0 +1,14 @@ +# This is a very very very very very very very very very very very very very very very very very very very very very long line. +# pylint: disable=line-too-long, print-statement +"""Make sure enable/disable pragmas work for messages that are applied to lines and not syntax nodes. + +A disable pragma for a message that applies to nodes is applied to the whole +block if it comes before the first statement (excluding the docstring). For +line-based messages, this behavior needs to be altered to really only apply to +the enclosed lines. +""" +# pylint: enable=line-too-long + +__revision__ = '1' + +print 'This is a very long line which the linter will warn about, now that line-too-long has been enabled again.' diff --git a/pylint/test/input/func_dotted_ancestor.py b/pylint/test/input/func_dotted_ancestor.py new file mode 100644 index 0000000..0603524 --- /dev/null +++ b/pylint/test/input/func_dotted_ancestor.py @@ -0,0 +1,11 @@ +"""bla""" +# pylint: disable=no-absolute-import +__revision__ = 'yo' + + +from input import func_w0233 + +class Aaaa(func_w0233.AAAA): + """test dotted name in ancestors""" + def __init__(self): + func_w0233.AAAA.__init__(self) diff --git a/pylint/test/input/func_e0001_py30.py b/pylint/test/input/func_e0001_py30.py new file mode 100644 index 0000000..9c1b727 --- /dev/null +++ b/pylint/test/input/func_e0001_py30.py @@ -0,0 +1,12 @@ +"""test string exception +""" + +__revision__ = '' + +def function1(): + """hehehe""" + raise "String Exception" + +def function2(): + """hehehe""" + raise 'exception', 'message' diff --git a/pylint/test/input/func_e0011.py b/pylint/test/input/func_e0011.py new file mode 100644 index 0000000..f2bb592 --- /dev/null +++ b/pylint/test/input/func_e0011.py @@ -0,0 +1,5 @@ +# pylint:bouboule=1 +"""check unknown option +""" +__revision__ = 1 + diff --git a/pylint/test/input/func_e0012.py b/pylint/test/input/func_e0012.py new file mode 100644 index 0000000..b50c9e5 --- /dev/null +++ b/pylint/test/input/func_e0012.py @@ -0,0 +1,5 @@ +# pylint:enable=W04044 +"""check unknown option +""" +__revision__ = 1 + diff --git a/pylint/test/input/func_e0101.py b/pylint/test/input/func_e0101.py new file mode 100644 index 0000000..2bf5a28 --- /dev/null +++ b/pylint/test/input/func_e0101.py @@ -0,0 +1,35 @@ +# pylint: disable=R0903 +"""test __init__ return +""" + +__revision__ = 'yo' + +class MyClass(object): + """dummy class""" + + def __init__(self): + return 1 + +class MyClass2(object): + """dummy class""" + + def __init__(self): + return + +class MyClass3(object): + """dummy class""" + + def __init__(self): + return None + +class MyClass4(object): + """dummy class""" + + def __init__(self): + yield None + +class MyClass5(object): + """dummy class""" + + def __init__(self): + self.callable = lambda: (yield None) diff --git a/pylint/test/input/func_e0108.py b/pylint/test/input/func_e0108.py new file mode 100644 index 0000000..2ed2ce1 --- /dev/null +++ b/pylint/test/input/func_e0108.py @@ -0,0 +1,14 @@ +"""Check for duplicate function arguments.""" +__revision__ = 1 + +def foo1(_, _): + """Function with duplicate argument name.""" + pass + +def foo2(_, *_): + """Function with duplicate argument name.""" + pass + +def foo3(_, _=3): + """Function with duplicate argument name.""" + pass diff --git a/pylint/test/input/func_e0203.py b/pylint/test/input/func_e0203.py new file mode 100644 index 0000000..d86f479 --- /dev/null +++ b/pylint/test/input/func_e0203.py @@ -0,0 +1,19 @@ +"""check for method without self as first argument +""" +from __future__ import print_function +__revision__ = 0 + + +class Abcd(object): + """dummy class""" + def __init__(self): + pass + + def abcd(yoo): + """another test""" + + abcd = classmethod(abcd) + + def edf(self): + """justo ne more method""" + print('yapudju in', self) diff --git a/pylint/test/input/func_e0204.py b/pylint/test/input/func_e0204.py new file mode 100644 index 0000000..7ab9cff --- /dev/null +++ b/pylint/test/input/func_e0204.py @@ -0,0 +1,19 @@ +"""check for method without self as first argument +""" +from __future__ import print_function +__revision__ = 0 + + +class Abcd(object): + """dummy class""" + + def __init__(truc): + """method without self""" + print(1) + + def abdc(yoo): + """another test""" + print(yoo) + def edf(self): + """just another method""" + print('yapudju in', self) diff --git a/pylint/test/input/func_e0206.py b/pylint/test/input/func_e0206.py new file mode 100644 index 0000000..a9f5790 --- /dev/null +++ b/pylint/test/input/func_e0206.py @@ -0,0 +1,20 @@ +# pylint: disable=R0903 +"""check for interface which are not classes""" + +__revision__ = None + +class Abcd(object): + """dummy""" + __implements__ = __revision__ + + def __init__(self): + self.attr = None + +class Cdef(object): + """dummy""" + __implements__ = (__revision__, Abcd) + + def __init__(self): + pass + + diff --git a/pylint/test/input/func_e0601.py b/pylint/test/input/func_e0601.py new file mode 100644 index 0000000..122ba01 --- /dev/null +++ b/pylint/test/input/func_e0601.py @@ -0,0 +1,9 @@ +"""test local variable used before assignment +""" +from __future__ import print_function +__revision__ = 0 + +def function(): + """dummy""" + print(aaaa) + aaaa = 1 diff --git a/pylint/test/input/func_e0604.py b/pylint/test/input/func_e0604.py new file mode 100644 index 0000000..d077f31 --- /dev/null +++ b/pylint/test/input/func_e0604.py @@ -0,0 +1,13 @@ +"""Test for invalid objects in a module's __all__ variable. + +""" +# pylint: disable=R0903,R0201,W0612 + +__revision__ = 0 + +def some_function(): + """Just a function.""" + pass + + +__all__ = [some_function] diff --git a/pylint/test/input/func_e12xx.py b/pylint/test/input/func_e12xx.py new file mode 100644 index 0000000..67475d1 --- /dev/null +++ b/pylint/test/input/func_e12xx.py @@ -0,0 +1,27 @@ +# pylint: disable=E1101, no-absolute-import +"""Test checking of log format strings +""" + +__revision__ = '' + +import logging + +def pprint(): + """Test string format in logging statements. + """ + # These should all emit lint errors: + logging.info(0, '') # 1205 + logging.info('', '') # 1205 + logging.info('%s%', '') # 1201 + logging.info('%s%s', '') # 1206 + logging.info('%s%y', '', '') # 1200 + logging.info('%s%s', '', '', '') # 1205 + + # These should be okay: + logging.info(1) + logging.info(True) + logging.info('') + logging.info('%s%') + logging.info('%s', '') + logging.info('%s%%', '') + logging.info('%s%s', '', '') diff --git a/pylint/test/input/func_e13xx.py b/pylint/test/input/func_e13xx.py new file mode 100644 index 0000000..e2bd77e --- /dev/null +++ b/pylint/test/input/func_e13xx.py @@ -0,0 +1,21 @@ +"""test string format error +""" +# pylint: disable=print-statement +__revision__ = 1 + +PARG_1 = PARG_2 = PARG_3 = 1 + +def pprint(): + """Test string format + """ + print "%s %s" % {'PARG_1': 1, 'PARG_2': 2} # E1306 + print "%s" % (PARG_1, PARG_2) # E1305 + print "%(PARG_1)d %d" % {'PARG_1': 1, 'PARG_2': 2} # E1302 + print "%(PARG_1)d %(PARG_2)d" % {'PARG_1': 1} # E1304 + print "%(PARG_1)d %(PARG_2)d" % {'PARG_1': 1, 'PARG_2':2, 'PARG_3':3}#W1301 + print "%(PARG_1)d %(PARG_2)d" % {'PARG_1': 1, 2:3} # W1300 E1304 + print "%(PARG_1)d %(PARG_2)d" % (2, 3) # 1303 + print "%(PARG_1)d %(PARG_2)d" % [2, 3] # 1303 + print "%2z" % PARG_1 + print "strange format %2" % PARG_2 + print "works in 3 %a" % 1 diff --git a/pylint/test/input/func_empty_module.py b/pylint/test/input/func_empty_module.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/pylint/test/input/func_empty_module.py diff --git a/pylint/test/input/func_eval_used.py b/pylint/test/input/func_eval_used.py new file mode 100644 index 0000000..c58b69c --- /dev/null +++ b/pylint/test/input/func_eval_used.py @@ -0,0 +1,13 @@ +"""test for eval usage""" + +__revision__ = 0 + +eval('os.listdir(".")') +eval('os.listdir(".")', globals={}) + +eval('os.listdir(".")', globals=globals()) + +def func(): + """ eval in local scope""" + eval('b = 1') + diff --git a/pylint/test/input/func_excess_escapes.py b/pylint/test/input/func_excess_escapes.py new file mode 100644 index 0000000..178ace8 --- /dev/null +++ b/pylint/test/input/func_excess_escapes.py @@ -0,0 +1,30 @@ +# pylint:disable=W0105, W0511 +"""Stray backslash escapes may be missing a raw-string prefix.""" + +__revision__ = '$Id$' + +# Bad escape sequences, which probably don't do what you expect. +A = "\[\]\\" +assert '\/' == '\\/' +ESCAPE_BACKSLASH = '\`' + +# Valid escape sequences. +NEWLINE = "\n" +OLD_ESCAPES = '\a\b\f\n\t\r\v' +HEX = '\xad\x0a\x0d' +FALSE_OCTAL = '\o123\o000' # Not octal in Python +OCTAL = '\123\000' +NOT_OCTAL = '\888\999' +NUL = '\0' +UNICODE = u'\u1234' +HIGH_UNICODE = u'\U0000abcd' +QUOTES = '\'\"' +LITERAL_NEWLINE = '\ +' +ESCAPE_UNICODE = "\\\\n" + +# Bad docstring +"""Even in a docstring + +You shouldn't have ambiguous text like: C:\Program Files\alpha +""" diff --git a/pylint/test/input/func_exec_used_py30.py b/pylint/test/input/func_exec_used_py30.py new file mode 100644 index 0000000..dbcc024 --- /dev/null +++ b/pylint/test/input/func_exec_used_py30.py @@ -0,0 +1,13 @@ +"""test global statement""" + +__revision__ = 0 + +exec('a = __revision__') +exec('a = 1', globals={}) + +exec('a = 1', globals=globals()) + +def func(): + """exec in local scope""" + exec('b = 1') + diff --git a/pylint/test/input/func_f0401.py b/pylint/test/input/func_f0401.py new file mode 100644 index 0000000..66e1240 --- /dev/null +++ b/pylint/test/input/func_f0401.py @@ -0,0 +1,9 @@ +"""test failed import +""" +from __future__ import absolute_import, print_function +__revision__ = 0 + +def function(): + """yo""" + from tutu import toto + print(toto) diff --git a/pylint/test/input/func_first_arg.py b/pylint/test/input/func_first_arg.py new file mode 100644 index 0000000..efff51d --- /dev/null +++ b/pylint/test/input/func_first_arg.py @@ -0,0 +1,42 @@ +# pylint: disable=C0111, W0232 +"""check for methods first arguments +""" + +__revision__ = 0 + + +class Obj(object): + # C0202, classmethod + def __new__(something): + pass + + # C0202, classmethod + def class1(cls): + pass + class1 = classmethod(class1) + + def class2(other): + pass + class2 = classmethod(class2) + + +class Meta(type): + # C0204, metaclass __new__ + def __new__(other, name, bases, dct): + pass + + # C0203, metaclass method + def method1(cls): + pass + + def method2(other): + pass + + # C0205, metaclass classmethod + def class1(mcs): + pass + class1 = classmethod(class1) + + def class2(other): + pass + class2 = classmethod(class2) diff --git a/pylint/test/input/func_fixme.py b/pylint/test/input/func_fixme.py new file mode 100644 index 0000000..9210be6 --- /dev/null +++ b/pylint/test/input/func_fixme.py @@ -0,0 +1,15 @@ +"""docstring""" +# pylint: disable=W0612 +__revision__ = '' + +# FIXME: beep + + +def function(): + '''XXX:bop''' + variable = "FIXME: Ignore me!" + test = "text" # FIXME: Valid test + + # TODO: Do something with the variables + xxx = "n/a" # XXX: Fix this later + #FIXME: no space after hash diff --git a/pylint/test/input/func_i0011.py b/pylint/test/input/func_i0011.py new file mode 100644 index 0000000..2b2f445 --- /dev/null +++ b/pylint/test/input/func_i0011.py @@ -0,0 +1,5 @@ +# pylint:disable=W0404 +"""check warning on local disabling +""" +__revision__ = 1 + diff --git a/pylint/test/input/func_i0012.py b/pylint/test/input/func_i0012.py new file mode 100644 index 0000000..aa646c6 --- /dev/null +++ b/pylint/test/input/func_i0012.py @@ -0,0 +1,5 @@ +# pylint:enable=W0404 +"""check warning on local enabling +""" +__revision__ = 1 + diff --git a/pylint/test/input/func_i0013.py b/pylint/test/input/func_i0013.py new file mode 100644 index 0000000..0a3f833 --- /dev/null +++ b/pylint/test/input/func_i0013.py @@ -0,0 +1,8 @@ +# pylint: skip-file +"""disable-all is usable as an inline option""" + +# no warning should be issued +try: + import this +except: + pass diff --git a/pylint/test/input/func_i0014.py b/pylint/test/input/func_i0014.py new file mode 100644 index 0000000..63ff37c --- /dev/null +++ b/pylint/test/input/func_i0014.py @@ -0,0 +1,8 @@ +# pylint: disable-all +"""disable-all is usable as an inline option""" + +# no warning should be issued +try: + import this +except: + pass diff --git a/pylint/test/input/func_i0020.py b/pylint/test/input/func_i0020.py new file mode 100644 index 0000000..8c0fe9f --- /dev/null +++ b/pylint/test/input/func_i0020.py @@ -0,0 +1,8 @@ +"""Test for reporting of suppressed messages.""" + +__revision__ = 0 + +def suppressed(): + """A function with an unused variable.""" + # pylint: disable=W0612 + var = 0 diff --git a/pylint/test/input/func_i0022.py b/pylint/test/input/func_i0022.py new file mode 100644 index 0000000..f5b308f --- /dev/null +++ b/pylint/test/input/func_i0022.py @@ -0,0 +1,22 @@ +"""Deprecated suppression style.""" + +__revision__ = None + +a = 1 # pylint: disable=invalid-name +b = 1 # pylint: disable-msg=invalid-name + +# pylint: disable=invalid-name +c = 1 +# pylint: enable=invalid-name + +# pylint: disable-msg=invalid-name +d = 1 +# pylint: enable-msg=invalid-name + +# pylint: disable-msg=C0103 +e = 1 +# pylint: enable-msg=C0103 + +# pylint: disable=C0103 +f = 1 +# pylint: enable=C0103 diff --git a/pylint/test/input/func_import_syntax_error.py b/pylint/test/input/func_import_syntax_error.py new file mode 100644 index 0000000..42af4d0 --- /dev/null +++ b/pylint/test/input/func_import_syntax_error.py @@ -0,0 +1,2 @@ +# pylint: disable=no-absolute-import +import syntax_error diff --git a/pylint/test/input/func_indent.py b/pylint/test/input/func_indent.py new file mode 100644 index 0000000..c593b49 --- /dev/null +++ b/pylint/test/input/func_indent.py @@ -0,0 +1,24 @@ +# pylint: disable=print-statement +"""docstring""" +__revision__ = '$Id: func_indent.py,v 1.4 2003-10-17 21:59:31 syt Exp $' + +def totoo(): + """docstring""" + print 'malindented' + +def tutuu(): + """docstring""" + print 'good indentation' + +def titii(): + """also malindented""" + 1 # and this. + +def tataa(kdict): + """blank line unindented""" + for key in ['1', '2', '3']: + key = key.lower() + + if kdict.has_key(key): + del kdict[key] + diff --git a/pylint/test/input/func_init_vars.py b/pylint/test/input/func_init_vars.py new file mode 100644 index 0000000..154fe3e --- /dev/null +++ b/pylint/test/input/func_init_vars.py @@ -0,0 +1,45 @@ +"""Checks that class variables are seen as inherited ! +""" +# pylint: disable=print-statement, too-few-public-methods +__revision__ = '' + + +class MyClass(object): + """Inherits from nothing + """ + + def __init__(self): + self.var = {} + + def met(self): + """Checks that base_var is seen as defined outside '__init__' + """ + self.var[1] = 'one' + self.base_var = 'one' + print self.base_var, self.var + + def met2(self): + """dummy method""" + print self +class MySubClass(MyClass): + """Inherits from MyClass + """ + class_attr = 1 + + def __init__(self): + MyClass.__init__(self) + self.var2 = 2 + print self.__doc__ + print self.__dict__ + print self.__class__ + + def met2(self): + """Checks that var is seen as defined outside '__init__' + """ + self.var[1] = 'one' + self.var2 += 1 + print self.class_attr + +if __name__ == '__main__': + OBJ = MyClass() + OBJ.met() diff --git a/pylint/test/input/func_interfaces.py b/pylint/test/input/func_interfaces.py new file mode 100644 index 0000000..21f42fb --- /dev/null +++ b/pylint/test/input/func_interfaces.py @@ -0,0 +1,112 @@ +# pylint:disable=R0201, print-statement +"""docstring""" +__revision__ = '' + +class Interface(object): + """base class for interfaces""" + +class IMachin(Interface): + """docstring""" + def truc(self): + """docstring""" + + def troc(self, argument): + """docstring""" + +class Correct1(object): + """docstring""" + __implements__ = IMachin + + def __init__(self): + pass + + def truc(self): + """docstring""" + pass + + def troc(self, argument): + """docstring""" + pass + +class Correct2(object): + """docstring""" + __implements__ = (IMachin,) + + def __init__(self): + pass + + def truc(self): + """docstring""" + pass + + def troc(self, argument): + """docstring""" + print argument + +class MissingMethod(object): + """docstring""" + __implements__ = IMachin, + + def __init__(self): + pass + + def troc(self, argument): + """docstring""" + print argument + + def other(self): + """docstring""" + +class BadArgument(object): + """docstring""" + __implements__ = (IMachin,) + + def __init__(self): + pass + + def truc(self): + """docstring""" + pass + + def troc(self): + """docstring""" + pass + +class InterfaceCantBeFound(object): + """docstring""" + __implements__ = undefined + + def __init__(self): + """only to make pylint happier""" + + def please(self): + """public method 1/2""" + + def besilent(self): + """public method 2/2""" + +class InterfaceCanNowBeFound(object): + """docstring""" + __implements__ = BadArgument.__implements__ + Correct2.__implements__ + + def __init__(self): + """only to make pylint happier""" + + def please(self): + """public method 1/2""" + + def besilent(self): + """public method 2/2""" + + +class EmptyImplements(object): + """no pb""" + __implements__ = () + def __init__(self): + """only to make pylint happier""" + + def please(self): + """public method 1/2""" + + def besilent(self): + """public method 2/2""" diff --git a/pylint/test/input/func_invalid_sequence_index.py b/pylint/test/input/func_invalid_sequence_index.py new file mode 100644 index 0000000..b60e0b5 --- /dev/null +++ b/pylint/test/input/func_invalid_sequence_index.py @@ -0,0 +1,210 @@ +"""Errors for invalid sequence indices""" +# pylint: disable=too-few-public-methods, no-self-use + +__revision__ = 0 + +TESTLIST = [1, 2, 3] +TESTTUPLE = (1, 2, 3) +TESTSTR = '123' + +# getitem tests with bad indices +def function1(): + """list index is a function""" + return TESTLIST[id] + +def function2(): + """list index is None""" + return TESTLIST[None] + +def function3(): + """list index is a float expression""" + return TESTLIST[float(0)] + +def function4(): + """list index is a str constant""" + return TESTLIST['0'] + +def function5(): + """list index does not implement __index__""" + class NonIndexType(object): + """Class without __index__ method""" + pass + + return TESTLIST[NonIndexType()] + +def function6(): + """Tuple index is None""" + return TESTTUPLE[None] + +def function7(): + """String index is None""" + return TESTSTR[None] + +def function8(): + """Index of subclass of tuple is None""" + class TupleTest(tuple): + """Subclass of tuple""" + pass + return TupleTest()[None] + +# getitem tests with good indices +def function9(): + """list index is an int constant""" + return TESTLIST[0] # no error + +def function10(): + """list index is a integer expression""" + return TESTLIST[int(0.0)] # no error + +def function11(): + """list index is a slice""" + return TESTLIST[slice(1, 2, 3)] # no error + +def function12(): + """list index implements __index__""" + class IndexType(object): + """Class with __index__ method""" + def __index__(self): + """Allow objects of this class to be used as slice indices""" + return 0 + + return TESTLIST[IndexType()] # no error + +def function13(): + """list index implements __index__ in a superclass""" + class IndexType(object): + """Class with __index__ method""" + def __index__(self): + """Allow objects of this class to be used as slice indices""" + return 0 + + class IndexSubType(IndexType): + """Class with __index__ in parent""" + pass + + return TESTLIST[IndexSubType()] # no error + +def function14(): + """Tuple index is an int constant""" + return TESTTUPLE[0] + +def function15(): + """String index is an int constant""" + return TESTSTR[0] + +def function16(): + """Index of subclass of tuple is an int constant""" + class TupleTest(tuple): + """Subclass of tuple""" + pass + return TupleTest()[0] # no error + +def function17(): + """Index of subclass of tuple with custom __getitem__ is None""" + class TupleTest(tuple): + """Subclass of tuple with custom __getitem__""" + def __getitem__(self, index): + """Allow non-integer indices""" + return 0 + return TupleTest()[None] # no error + +def function18(): + """Index of subclass of tuple with __getitem__ in superclass is None""" + class TupleTest(tuple): + """Subclass of tuple with custom __getitem__""" + def __getitem__(self, index): + """Allow non-integer indices""" + return 0 + + class SubTupleTest(TupleTest): + """Subclass of a subclass of tuple""" + pass + + return SubTupleTest()[None] # no error + +# Test with set and delete statements +def function19(): + """Set with None and integer indices""" + TESTLIST[None] = 0 + TESTLIST[0] = 0 # no error + +def function20(): + """Delete with None and integer indicies""" + del TESTLIST[None] + del TESTLIST[0] # no error + +def function21(): + """Set and delete on a subclass of list""" + class ListTest(list): + """Inherit all list get/set/del handlers""" + pass + test = ListTest() + + # Set and delete with invalid indices + test[None] = 0 + del test[None] + + # Set and delete with valid indices + test[0] = 0 # no error + del test[0] # no error + +def function22(): + """Get, set, and delete on a subclass of list that overrides __setitem__""" + class ListTest(list): + """Override setitem but not get or del""" + def __setitem__(self, key, value): + pass + test = ListTest() + + test[None][0] = 0 # failure on the getitem with None + del test[None] + + test[0][0] = 0 # getitem with int and setitem with int, no error + test[None] = 0 # setitem overridden, no error + test[0] = 0 # setitem with int, no error + del test[0] # delitem with int, no error + +def function23(): + """Get, set, and delete on a subclass of list that overrides __delitem__""" + class ListTest(list): + """Override delitem but not get or set""" + def __delitem__(self, key): + pass + test = ListTest() + + test[None][0] = 0 # failure on the getitem with None + test[None] = 0 # setitem with invalid index + + test[0][0] = 0 # getitem with int and setitem with int, no error + test[0] = 0 # setitem with int, no error + del test[None] # delitem overriden, no error + del test[0] # delitem with int, no error + +def function24(): + """Get, set, and delete on a subclass of list that overrides __getitem__""" + class ListTest(list): + """Override gelitem but not del or set""" + def __getitem__(self, key): + pass + test = ListTest() + + test[None] = 0 # setitem with invalid index + del test[None] # delitem with invalid index + + test[None][0] = 0 # getitem overriden, no error + test[0][0] = 0 # getitem with int and setitem with int, no error + test[0] = 0 # setitem with int, no error + del test[0] # delitem with int, no error + +# Teest ExtSlice usage +def function25(): + """Extended slice used with a list""" + return TESTLIST[..., 0] + +def function26(): + """Extended slice used with an object that implements __getitem__""" + class ExtSliceTest(object): + """Permit extslice syntax by implementing __getitem__""" + def __getitem__(self, index): + return 0 + return ExtSliceTest[..., 0] # no error diff --git a/pylint/test/input/func_keyword_repeat.py b/pylint/test/input/func_keyword_repeat.py new file mode 100644 index 0000000..eeb733a --- /dev/null +++ b/pylint/test/input/func_keyword_repeat.py @@ -0,0 +1,11 @@ +"""Test repeated keyword argument checker""" +__revision__ = '' + +def function_default_arg(one=1, two=2): + """fonction with default value""" + return two, one + +function_default_arg(two=5, two=7) +function_default_arg(two=5, one=7, one='bob') + + diff --git a/pylint/test/input/func_kwoa_py30.py b/pylint/test/input/func_kwoa_py30.py new file mode 100644 index 0000000..4be5302 --- /dev/null +++ b/pylint/test/input/func_kwoa_py30.py @@ -0,0 +1,12 @@ +# pylint: disable=C0121, C0102 +'''A little testscript for PEP 3102 and pylint''' +def function(*, foo): + '''A function for testing''' + print(foo) + +function(foo=1) + +foo = 1 +function(foo) + +function(1) diff --git a/pylint/test/input/func_logging_not_lazy_with_logger.py b/pylint/test/input/func_logging_not_lazy_with_logger.py new file mode 100644 index 0000000..afbe285 --- /dev/null +++ b/pylint/test/input/func_logging_not_lazy_with_logger.py @@ -0,0 +1,14 @@ +"""Logging warnings using a logger class.""" +from __future__ import absolute_import +__revision__ = '' + +import logging + + +LOG = logging.getLogger("domain") +LOG.debug("%s" % "junk") +LOG.log(logging.DEBUG, "%s" % "junk") +LOG2 = LOG.debug +LOG2("%s" % "junk") + +logging.getLogger("domain").debug("%s" % "junk") diff --git a/pylint/test/input/func_loopvar_in_dict_comp_py27.py b/pylint/test/input/func_loopvar_in_dict_comp_py27.py new file mode 100644 index 0000000..312eee7 --- /dev/null +++ b/pylint/test/input/func_loopvar_in_dict_comp_py27.py @@ -0,0 +1,8 @@ +"""Tests for loopvar-in-closure.""" + +__revision__ = 0 + + +def bad_case(): + """Loop variable from dict comprehension.""" + return {x: lambda: x for x in range(10)} diff --git a/pylint/test/input/func_method_could_be_function.py b/pylint/test/input/func_method_could_be_function.py new file mode 100644 index 0000000..7544793 --- /dev/null +++ b/pylint/test/input/func_method_could_be_function.py @@ -0,0 +1,60 @@ +# pylint: disable=R0903,R0922,W0232,print-statement +"""test detection of method which could be a function""" + +__revision__ = None + +class Toto(object): + """bla bal abl""" + + def __init__(self): + self.aaa = 2 + + def regular_method(self): + """this method is a real method since it access to self""" + self.function_method() + + def function_method(self): + """this method isn' a real method since it doesn't need self""" + print 'hello' + + +class Base(object): + """an abstract class""" + + def __init__(self): + self.aaa = 2 + + def check(self, arg): + """an abstract method, could not be a function""" + raise NotImplementedError + + +class Sub(Base): + """a concret class""" + + def check(self, arg): + """a concret method, could not be a function since it need + polymorphism benefits + """ + return arg == 0 + +class Super(object): + """same as before without abstract""" + attr = 1 + def method(self): + """regular""" + print self.attr + +class Sub1(Super): + """override method with need for self""" + def method(self): + """no i can not be a function""" + print 42 + + def __len__(self): + """no i can not be a function""" + print 42 + + def __cmp__(self, other): + """no i can not be a function""" + print 42 diff --git a/pylint/test/input/func_module___dict__.py b/pylint/test/input/func_module___dict__.py new file mode 100644 index 0000000..5451422 --- /dev/null +++ b/pylint/test/input/func_module___dict__.py @@ -0,0 +1,9 @@ +"""http://www.logilab.org/ticket/6949.""" +from __future__ import print_function +__revision__ = None + +print(__dict__ is not None) + +__dict__ = {} + +print(__dict__ is not None) diff --git a/pylint/test/input/func_more_e0604.py b/pylint/test/input/func_more_e0604.py new file mode 100644 index 0000000..6c39e1c --- /dev/null +++ b/pylint/test/input/func_more_e0604.py @@ -0,0 +1,9 @@ +"""Test for invalid objects in a module's __all__ variable. + +""" +# pylint: disable=R0903,R0201,W0612 + +__revision__ = 0 + + +__all__ = [1] diff --git a/pylint/test/input/func_nameerror_on_string_substitution.py b/pylint/test/input/func_nameerror_on_string_substitution.py new file mode 100644 index 0000000..be7b5c8 --- /dev/null +++ b/pylint/test/input/func_nameerror_on_string_substitution.py @@ -0,0 +1,8 @@ +"""pylint doesn't see the NameError in this module""" + +__revision__ = None + +MSG = "hello %s" % MSG + +MSG2 = ("hello %s" % + MSG2) diff --git a/pylint/test/input/func_no_dummy_redefined.py b/pylint/test/input/func_no_dummy_redefined.py new file mode 100644 index 0000000..7d40f81 --- /dev/null +++ b/pylint/test/input/func_no_dummy_redefined.py @@ -0,0 +1,14 @@ +"""Make sure warnings about redefinitions do not trigger for dummy variables.""" +__revision__ = 0 + + +_, INTERESTING = 'a=b'.split('=') + +value = 10 + + +def clobbering(): + """Clobbers a dummy name from the outer scope.""" + value = 9 + for _ in range(7): + print value # pylint: disable=print-statement diff --git a/pylint/test/input/func_noerror___init___return_from_inner_function.py b/pylint/test/input/func_noerror___init___return_from_inner_function.py new file mode 100644 index 0000000..397b0fc --- /dev/null +++ b/pylint/test/input/func_noerror___init___return_from_inner_function.py @@ -0,0 +1,13 @@ +# pylint: disable=R0903 +"""#10075""" + +__revision__ = 1 + +class Aaa(object): + """docstring""" + def __init__(self): + def inner_function(arg): + """inner docstring""" + return arg + 4 + self.func = inner_function + diff --git a/pylint/test/input/func_noerror_access_attr_before_def_false_positive.py b/pylint/test/input/func_noerror_access_attr_before_def_false_positive.py new file mode 100644 index 0000000..8c28599 --- /dev/null +++ b/pylint/test/input/func_noerror_access_attr_before_def_false_positive.py @@ -0,0 +1,98 @@ +#pylint: disable=C0103,R0904,R0903,W0201,old-style-class,print-statement,no-absolute-import +""" +This module demonstrates a possible problem of pyLint with calling __init__ s +from inherited classes. +Initializations done there are not considered, which results in Error E0203 for +self.cookedq. +""" + +__revision__ = 'yo' + +import telnetlib + +class SeeTelnet(telnetlib.Telnet): + """ + Extension of telnetlib. + """ + + def __init__(self, host=None, port=0): + """ + Constructor. + When called without arguments, create an unconnected instance. + With a hostname argument, it connects the instance; a port + number is optional. + Parameter: + - host: IP address of the host + - port: Port number + """ + telnetlib.Telnet.__init__(self, host, port) + + def readUntilArray(self, matches, _=None): + """ + Read until a given string is encountered or until timeout. + ... + """ + self.process_rawq() + maxLength = 0 + for match in matches: + if len(match) > maxLength: + maxLength = len(match) + +class Base(object): + """bla bla""" + dougloup_papa = None + + def __init__(self): + self._var = False + +class Derived(Base): + """derived blabla""" + dougloup_moi = None + def Work(self): + """do something""" + # E0203 - Access to member '_var' before its definition + if self._var: + print "True" + else: + print "False" + self._var = True + + # E0203 - Access to member 'dougloup_papa' before its definition + if self.dougloup_papa: + print 'dougloup !' + self.dougloup_papa = True + # E0203 - Access to member 'dougloup_moi' before its definition + if self.dougloup_moi: + print 'dougloup !' + self.dougloup_moi = True + + +class QoSALConnection(object): + """blabla""" + + _the_instance = None + + def __new__(cls): + if cls._the_instance is None: + cls._the_instance = object.__new__(cls) + return cls._the_instance + + def __init__(self): + pass + +class DefinedOutsideInit(object): + """use_attr is seen as the method defining attr because its in + first position + """ + def __init__(self): + self.reset() + + def use_attr(self): + """use and set members""" + if self.attr: + print 'hop' + self.attr = 10 + + def reset(self): + """reset members""" + self.attr = 4 diff --git a/pylint/test/input/func_noerror_base_init_vars.py b/pylint/test/input/func_noerror_base_init_vars.py new file mode 100644 index 0000000..f552eef --- /dev/null +++ b/pylint/test/input/func_noerror_base_init_vars.py @@ -0,0 +1,35 @@ +# pylint:disable=R0201, print-statement, too-few-public-methods +"""Checks that class variables are seen as inherited ! +""" +__revision__ = '' + +class BaseClass(object): + """A simple base class + """ + + def __init__(self): + self.base_var = {} + + def met(self): + """yo""" + def meeting(self, with_): + """ye""" + return with_ +class MyClass(BaseClass): + """Inherits from BaseClass + """ + + def __init__(self): + BaseClass.__init__(self) + self.var = {} + + def met(self): + """Checks that base_var is not seen as defined outsite '__init__' + """ + self.var[1] = 'one' + self.base_var[1] = 'one' + print self.base_var, self.var + +if __name__ == '__main__': + OBJ = MyClass() + OBJ.met() diff --git a/pylint/test/input/func_noerror_builtin_module_test.py b/pylint/test/input/func_noerror_builtin_module_test.py new file mode 100644 index 0000000..f73694a --- /dev/null +++ b/pylint/test/input/func_noerror_builtin_module_test.py @@ -0,0 +1,9 @@ +"""test import from a builtin module""" +from __future__ import absolute_import +__revision__ = None + +from math import log10 + +def log10_2(): + """bla bla bla""" + return log10(2) diff --git a/pylint/test/input/func_noerror_class_attributes.py b/pylint/test/input/func_noerror_class_attributes.py new file mode 100644 index 0000000..75fb435 --- /dev/null +++ b/pylint/test/input/func_noerror_class_attributes.py @@ -0,0 +1,17 @@ +"""Test that valid class attribute doesn't trigger errors""" +__revision__ = 'sponge bob' + +class Clazz(object): + "dummy class" + + def __init__(self): + self.topic = 5 + self._data = 45 + + def change_type(self, new_class): + """Change type""" + self.__class__ = new_class + + def do_nothing(self): + "I do nothing useful" + return self.topic + 56 diff --git a/pylint/test/input/func_noerror_class_decorators_py26.py b/pylint/test/input/func_noerror_class_decorators_py26.py new file mode 100644 index 0000000..541bb45 --- /dev/null +++ b/pylint/test/input/func_noerror_class_decorators_py26.py @@ -0,0 +1,8 @@ +"""test class decorator are recognized""" +# pylint: disable=R0903,W0232,C,no-absolute-import + +from logilab.common.deprecation import deprecated, class_moved + +@deprecated('This is a bad class name; use %s to rename' % class_moved) +class Foo: + '''foo goo''' diff --git a/pylint/test/input/func_noerror_classes_meth_could_be_a_function.py b/pylint/test/input/func_noerror_classes_meth_could_be_a_function.py new file mode 100644 index 0000000..bdf0da4 --- /dev/null +++ b/pylint/test/input/func_noerror_classes_meth_could_be_a_function.py @@ -0,0 +1,34 @@ +# pylint: disable=C0111,R0903,W0232 +""" +#2479 + +R0201 (formely W0212), Method could be a function shouldn't be emitted in case +like factory method pattern +""" +__revision__ = 1 + +class XAsub(object): + pass +class XBsub(XAsub): + pass +class XCsub(XAsub): + pass + +class Aimpl(object): + # disable "method could be a function" on classes which are not overriding + # the factory method because in that case the usage of polymorphism is not + # detected + # pylint: disable=R0201 + def makex(self): + return XAsub() + +class Bimpl(Aimpl): + + def makex(self): + return XBsub() + +class Cimpl(Aimpl): + + def makex(self): + return XCsub() + diff --git a/pylint/test/input/func_noerror_classes_meth_signature.py b/pylint/test/input/func_noerror_classes_meth_signature.py new file mode 100644 index 0000000..2aa5b18 --- /dev/null +++ b/pylint/test/input/func_noerror_classes_meth_signature.py @@ -0,0 +1,38 @@ +# pylint: disable=C0111,R0922,R0903,W0231 +"""#2485: +W0222 "Signature differs from overriden method" false positive +#18772: +no prototype consistency check for mangled methods +""" +__revision__ = 1 +class Super(object): + def __init__(self): + pass + + def __private(self): + pass + + def __private2_(self): + pass + + def ___private3(self): + pass + + def method(self, param): + raise NotImplementedError + +class Sub(Super): + def __init__(self, arg): + pass + + def __private(self, arg): + pass + + def __private2_(self, arg): + pass + + def ___private3(self, arg): + pass + + def method(self, param='abc'): + pass diff --git a/pylint/test/input/func_noerror_classes_protected_member_access.py b/pylint/test/input/func_noerror_classes_protected_member_access.py new file mode 100644 index 0000000..eeff97d --- /dev/null +++ b/pylint/test/input/func_noerror_classes_protected_member_access.py @@ -0,0 +1,25 @@ +""" +#3123: W0212 false positive on static method +""" +__revision__ = 1 + +class A3123(object): + """oypuee""" + _protected = 1 + def __init__(self): + pass + + + def cmeth(cls, val): + """set protected member""" + cls._protected = +val + + cmeth = classmethod(cmeth) + + def smeth(val): + """set protected member""" + A3123._protected += val + + smeth = staticmethod(smeth) + + prop = property(lambda self: self._protected) diff --git a/pylint/test/input/func_noerror_crash_122793.py b/pylint/test/input/func_noerror_crash_122793.py new file mode 100644 index 0000000..2bb3d2e --- /dev/null +++ b/pylint/test/input/func_noerror_crash_122793.py @@ -0,0 +1,9 @@ +# pylint: disable=C0121 +"""https://www.logilab.org/ticket/122793""" + +def gen(): + """dumb generator""" + yield + +GEN = gen() +next(GEN) diff --git a/pylint/test/input/func_noerror_crash_127416.py b/pylint/test/input/func_noerror_crash_127416.py new file mode 100644 index 0000000..3a04363 --- /dev/null +++ b/pylint/test/input/func_noerror_crash_127416.py @@ -0,0 +1,20 @@ +# pylint: disable=C0111,R0201,C0121 +""" +FUNCTIONALITY +""" + +class Example(object): + """ + @summary: Demonstrates pylint error caused by method expecting tuple + but called method does not return tuple + """ + + def method_expects_tuple(self, obj): + meth, args = self.method_doesnot_return_tuple(obj) + result = meth(args) + return result + + def method_doesnot_return_tuple(self, obj): + # we want to lock what we have in the inventory, not what is to have + # in the future + return {'success': obj} diff --git a/pylint/test/input/func_noerror_decorator_scope.py b/pylint/test/input/func_noerror_decorator_scope.py new file mode 100644 index 0000000..9c84d61 --- /dev/null +++ b/pylint/test/input/func_noerror_decorator_scope.py @@ -0,0 +1,19 @@ +# -*- pylint: disable=W0232,R0903,print-statement +"""Test that decorators sees the class namespace - just like +function default values does but function body doesn't. + +https://www.logilab.net/elo/ticket/3711 - bug finding decorator arguments +https://www.logilab.net/elo/ticket/5626 - name resolution bug inside classes +""" + +__revision__ = 0 + +class Test(object): + """test class""" + ident = lambda x: x + + @ident(ident) + def method(self, val=ident(7), func=ident): + """hop""" + print self + return func(val) diff --git a/pylint/test/input/func_noerror_e1101_13784.py b/pylint/test/input/func_noerror_e1101_13784.py new file mode 100644 index 0000000..b247b44 --- /dev/null +++ b/pylint/test/input/func_noerror_e1101_13784.py @@ -0,0 +1,15 @@ +"""cf #13784 +""" + +__revision__ = None + +def no_conjugate_member(magic_flag): + """should not raise E1101 on something.conjugate""" + if magic_flag: + something = 1.0 + else: + something = 1.0j + if isinstance(something, float): + return something + return something.conjugate() + diff --git a/pylint/test/input/func_noerror_e1101_9588_base_attr_aug_assign.py b/pylint/test/input/func_noerror_e1101_9588_base_attr_aug_assign.py new file mode 100644 index 0000000..03106a5 --- /dev/null +++ b/pylint/test/input/func_noerror_e1101_9588_base_attr_aug_assign.py @@ -0,0 +1,39 @@ +# pylint: disable=R0903 +""" +False positive case of E1101: + +The error is triggered when the attribute set in the base class is +modified with augmented assignment in a derived class. + +http://www.logilab.org/ticket/9588 +""" +__revision__ = 0 + +class BaseClass(object): + "The base class" + def __init__(self): + "Set an attribute." + self.e1101 = 1 + +class FalsePositiveClass(BaseClass): + "The first derived class which triggers the false positive" + def __init__(self): + "Augmented assignment triggers E1101." + BaseClass.__init__(self) + self.e1101 += 1 + + def countup(self): + "Consequently this also triggers E1101." + self.e1101 += 1 + +class NegativeClass(BaseClass): + "The second derived class, which does not trigger the error E1101" + def __init__(self): + "Ordinary assignment is OK." + BaseClass.__init__(self) + self.e1101 = self.e1101 + 1 + + def countup(self): + "No problem." + self.e1101 += 1 + diff --git a/pylint/test/input/func_noerror_e1101_but_getattr.py b/pylint/test/input/func_noerror_e1101_but_getattr.py new file mode 100644 index 0000000..529b413 --- /dev/null +++ b/pylint/test/input/func_noerror_e1101_but_getattr.py @@ -0,0 +1,23 @@ +"""don't want E1101 if __getattr__ is defined""" +from __future__ import print_function +__revision__ = None + +class MyString(object): + """proxied string""" + + def __init__(self, string): + self.string = string + + def __getattr__(self, attr): + return getattr(self.string, attr) + + def lower(self): + """string.lower""" + return self.string.lower() + + def upper(self): + """string.upper""" + return self.string.upper() + +MYSTRING = MyString("abc") +print(MYSTRING.title()) diff --git a/pylint/test/input/func_noerror_encoding.py b/pylint/test/input/func_noerror_encoding.py new file mode 100644 index 0000000..2e945a5 --- /dev/null +++ b/pylint/test/input/func_noerror_encoding.py @@ -0,0 +1,6 @@ +# -*- coding: ISO-8859-1 -*- +""" check correct encoding declaration +""" + +__revision__ = 'éééé' + diff --git a/pylint/test/input/func_noerror_except_pass.py b/pylint/test/input/func_noerror_except_pass.py new file mode 100644 index 0000000..5bb8011 --- /dev/null +++ b/pylint/test/input/func_noerror_except_pass.py @@ -0,0 +1,12 @@ +""" +#3205: W0704 (except doesn't do anything) false positive if some statements +follow a "pass" +""" +from __future__ import print_function +__revision__ = None + +try: + A = 2 +except ValueError: + pass # pylint: disable=W0107 + print(A) diff --git a/pylint/test/input/func_noerror_exception.py b/pylint/test/input/func_noerror_exception.py new file mode 100644 index 0000000..1c3d8b5 --- /dev/null +++ b/pylint/test/input/func_noerror_exception.py @@ -0,0 +1,7 @@ +""" module doc """ +__revision__ = '' + +class MyException(Exception): + """a custom exception with its *own* __init__ !!""" + def __init__(self, msg): + Exception.__init__(self, msg) diff --git a/pylint/test/input/func_noerror_external_classmethod_crash.py b/pylint/test/input/func_noerror_external_classmethod_crash.py new file mode 100644 index 0000000..318f01c --- /dev/null +++ b/pylint/test/input/func_noerror_external_classmethod_crash.py @@ -0,0 +1,21 @@ +# pylint: disable=W0232,R0903,W0613 +"""tagging a function as a class method cause a crash when checking for +signature overriding +""" + +def fetch_config(mainattr=None): + """return a class method""" + + def fetch_order(cls, attr, var): + """a class method""" + if attr == mainattr: + return var + return None + fetch_order = classmethod(fetch_order) + return fetch_order + +class Aaa(object): + """hop""" + fetch_order = fetch_config('A') + +__revision__ = None diff --git a/pylint/test/input/func_noerror_factory_method.py b/pylint/test/input/func_noerror_factory_method.py new file mode 100644 index 0000000..a7cff43 --- /dev/null +++ b/pylint/test/input/func_noerror_factory_method.py @@ -0,0 +1,23 @@ +# pylint: disable=R0903, print-statement +"""use new astroid context sensitive inference""" +__revision__ = 1 + +class Super(object): + """super class""" + def __init__(self): + self.bla = None + + def instance(cls): + """factory method""" + return cls() + instance = classmethod(instance) + +class Sub(Super): + """dub class""" + def method(self): + """specific method""" + print 'method called', self + +# should see the Sub.instance() is returning a Sub instance, not a Super +# instance +Sub.instance().method() diff --git a/pylint/test/input/func_noerror_function_as_method.py b/pylint/test/input/func_noerror_function_as_method.py new file mode 100644 index 0000000..e59fb5c --- /dev/null +++ b/pylint/test/input/func_noerror_function_as_method.py @@ -0,0 +1,18 @@ +# pylint: disable=R0903, print-statement +'''Test that a function is considered a method when looked up through a class. +''' +__revision__ = 1 + +class Clazz(object): + 'test class' + + def __init__(self, value): + self.value = value + +def func(arg1, arg2): + 'function that will be used as a method' + return arg1.value + arg2 + +Clazz.method = func + +print Clazz(1).method(2) diff --git a/pylint/test/input/func_noerror_genexp_in_class_scope.py b/pylint/test/input/func_noerror_genexp_in_class_scope.py new file mode 100644 index 0000000..5631026 --- /dev/null +++ b/pylint/test/input/func_noerror_genexp_in_class_scope.py @@ -0,0 +1,9 @@ +# pylint: disable=W0232,R0903 +"""class scope must be handled correctly in genexps""" + +__revision__ = '' + +class MyClass(object): + """ds""" + var1 = [] + var2 = list(value*2 for value in var1) diff --git a/pylint/test/input/func_noerror_indirect_interface.py b/pylint/test/input/func_noerror_indirect_interface.py new file mode 100644 index 0000000..cbd1ae4 --- /dev/null +++ b/pylint/test/input/func_noerror_indirect_interface.py @@ -0,0 +1,16 @@ +"""shows a bug where pylint can't find interfaces when they are +used indirectly. See input/indirect[123].py for details on the +setup""" +# pylint: disable=old-style-class, too-few-public-methods, no-absolute-import +__revision__ = None + +from input.indirect2 import AbstractToto + +class ConcreteToto(AbstractToto): + """abstract to implements an interface requiring machin to be defined""" + def __init__(self): + self.duh = 2 + + def machin(self): + """for ifacd""" + return self.helper()*2 diff --git a/pylint/test/input/func_noerror_inner_classes.py b/pylint/test/input/func_noerror_inner_classes.py new file mode 100644 index 0000000..84fb43d --- /dev/null +++ b/pylint/test/input/func_noerror_inner_classes.py @@ -0,0 +1,33 @@ +# pylint: disable=R0903 +"""Backend Base Classes for the schwelm user DB""" + +__revision__ = "alpha" + +class Aaa(object): + """docstring""" + def __init__(self): + self.__setattr__('a', 'b') + + + def one_public(self): + """docstring""" + pass + + def another_public(self): + """docstring""" + pass + +class Bbb(Aaa): + """docstring""" + pass + +class Ccc(Aaa): + """docstring""" + + class Ddd(Aaa): + """docstring""" + pass + + class Eee(Ddd): + """docstring""" + pass diff --git a/pylint/test/input/func_noerror_lambda_use_before_assign.py b/pylint/test/input/func_noerror_lambda_use_before_assign.py new file mode 100644 index 0000000..af2775c --- /dev/null +++ b/pylint/test/input/func_noerror_lambda_use_before_assign.py @@ -0,0 +1,8 @@ +"""https://www.logilab.net/elo/ticket/18862""" +from __future__ import print_function +__revision__ = 1 +def function(): + """hop""" + ggg = lambda: xxx + xxx = 1 + print(ggg()) diff --git a/pylint/test/input/func_noerror_long_utf8_line.py b/pylint/test/input/func_noerror_long_utf8_line.py new file mode 100644 index 0000000..6fba949 --- /dev/null +++ b/pylint/test/input/func_noerror_long_utf8_line.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +"""this utf-8 doc string have some non ASCII caracters like 'é', or '¢»ß'""" +### check also comments with some more non ASCII caracters like 'é' or '¢»ß' + +__revision__ = 1100 + +ASCII = "----------------------------------------------------------------------" +UTF_8 = "--------------------------------------------------------------------éé" + diff --git a/pylint/test/input/func_noerror_mcs_attr_access.py b/pylint/test/input/func_noerror_mcs_attr_access.py new file mode 100644 index 0000000..3310c49 --- /dev/null +++ b/pylint/test/input/func_noerror_mcs_attr_access.py @@ -0,0 +1,20 @@ +# pylint: disable=R0903, print-statement, metaclass-assignment +"""test attribute access on metaclass""" + + +__revision__ = 'yo' + +class Meta(type): + """the meta class""" + def __init__(cls, name, bases, dictionary): + super(Meta, cls).__init__(name, bases, dictionary) + print cls, cls._meta_args + delattr(cls, '_meta_args') + +class Test(object): + """metaclassed class""" + __metaclass__ = Meta + _meta_args = ('foo', 'bar') + + def __init__(self): + print '__init__', self diff --git a/pylint/test/input/func_noerror_nested_classes.py b/pylint/test/input/func_noerror_nested_classes.py new file mode 100644 index 0000000..56e57bb --- /dev/null +++ b/pylint/test/input/func_noerror_nested_classes.py @@ -0,0 +1,18 @@ +# pylint: disable=R0903, print-statement +"""crash test""" + +__revision__ = 1 + +class Temelekefe(object): + """gloubliboulga""" + + def __init__(self): + """nested class with function raise error""" + class Toto(object): + """toto nested class""" + def __init__(self): + self.attr = 2 + def toto_method(self): + """toto nested class method""" + print self + print 'error ?', self, Toto diff --git a/pylint/test/input/func_noerror_new_style_class_py_30.py b/pylint/test/input/func_noerror_new_style_class_py_30.py new file mode 100644 index 0000000..a33ae19 --- /dev/null +++ b/pylint/test/input/func_noerror_new_style_class_py_30.py @@ -0,0 +1,45 @@ +"""check builtin data descriptors such as mode and name attributes +on a file are correctly handled + +bug notified by Pierre Rouleau on 2005-04-24 +""" +from __future__ import print_function +__revision__ = None + +class File(file): # pylint: disable=file-builtin + """ Testing new-style class inheritance from file""" + + # + def __init__(self, name, mode="r", buffering=-1, verbose=False): + """Constructor""" + + self.was_modified = False + self.verbose = verbose + super(File, self).__init__(name, mode, buffering) + if self.verbose: + print("File %s is opened. The mode is: %s" % (self.name, + self.mode)) + + # + def write(self, a_string): + """ Write a string to the file.""" + + super(File, self).write(a_string) + self.was_modified = True + + # + def writelines(self, sequence): + """ Write a sequence of strings to the file. """ + + super(File, self).writelines(sequence) + self.was_modified = True + + # + def close(self): + """Close the file.""" + + if self.verbose: + print("Closing file %s" % self.name) + + super(File, self).close() + self.was_modified = False diff --git a/pylint/test/input/func_noerror_no_warning_docstring.py b/pylint/test/input/func_noerror_no_warning_docstring.py new file mode 100644 index 0000000..f8ee9bc --- /dev/null +++ b/pylint/test/input/func_noerror_no_warning_docstring.py @@ -0,0 +1,42 @@ +''' Test for inheritence ''' +from __future__ import print_function +__revision__ = 1 +# pylint: disable=too-few-public-methods +class AAAA(object): + ''' class AAAA ''' + + def __init__(self): + pass + + def method1(self): + ''' method 1 ''' + print(self) + + def method2(self): + ''' method 2 ''' + print(self) + +class BBBB(AAAA): + ''' class BBBB ''' + + def __init__(self): + AAAA.__init__(self) + + # should ignore docstring calling from class AAAA + def method1(self): + AAAA.method1(self) + +class CCCC(BBBB): + ''' class CCCC ''' + + def __init__(self): + BBBB.__init__(self) + + # should ignore docstring since CCCC is inherited from BBBB which is + # inherited from AAAA containing method2 + if __revision__: + def method2(self): + AAAA.method2(self) + else: + def method2(self): + AAAA.method1(self) diff --git a/pylint/test/input/func_noerror_nonregr.py b/pylint/test/input/func_noerror_nonregr.py new file mode 100644 index 0000000..c4c8c38 --- /dev/null +++ b/pylint/test/input/func_noerror_nonregr.py @@ -0,0 +1,13 @@ +# pylint: disable=W0106 +"""snippets of codes which have at some point made pylint crash""" + +__revision__ = 1 + +def function1(cbarg=lambda: None): + """ + File "/usr/lib/python2.4/site-packages/logilab/astroid/scoped_nodes.py", line +391, in mularg_class # this method doesn't exist anymore + i = self.args.args.index(argname) +ValueError: list.index(x): x not in list + """ + cbarg().x diff --git a/pylint/test/input/func_noerror_object_as_class_attribute.py b/pylint/test/input/func_noerror_object_as_class_attribute.py new file mode 100644 index 0000000..c69b2b9 --- /dev/null +++ b/pylint/test/input/func_noerror_object_as_class_attribute.py @@ -0,0 +1,19 @@ +# pylint: disable=R0903 +"""Test case for the problem described below : + - A class extends 'object' + - This class defines its own __init__() + * pylint will therefore check that baseclasses' init() + are called + - If this class defines an 'object' attribute, then pylint + will use this new definition when trying to retrieve + object.__init__() +""" + +__revision__ = None + +class Statement(object): + """ ... """ + def __init__(self): + pass + object = None + diff --git a/pylint/test/input/func_noerror_overloaded_operator.py b/pylint/test/input/func_noerror_overloaded_operator.py new file mode 100644 index 0000000..4e29946 --- /dev/null +++ b/pylint/test/input/func_noerror_overloaded_operator.py @@ -0,0 +1,21 @@ +# pylint: disable=C0111,R0903,print-statement +"""#3291""" +__revision__ = 1 + +class Myarray(object): + def __init__(self, array): + self.array = array + + def __mul__(self, val): + return Myarray(val) + + def astype(self): + return "ASTYPE", self + +def randint(maximum): + if maximum is not None: + return Myarray([1, 2, 3]) * 2 + else: + return int(5) + +print randint(1).astype() # we don't wan't an error for astype access diff --git a/pylint/test/input/func_noerror_overriden_method_varargs.py b/pylint/test/input/func_noerror_overriden_method_varargs.py new file mode 100644 index 0000000..afe3086 --- /dev/null +++ b/pylint/test/input/func_noerror_overriden_method_varargs.py @@ -0,0 +1,19 @@ +# pylint: disable=R0201,R0903 +"""docstring""" + +__revision__ = 1 + +class SuperClass(object): + """docstring""" + def impl(self, arg1, arg2): + """docstring""" + return arg1 + arg2 + +class MyClass(SuperClass): + """docstring""" + def impl(self, *args, **kwargs): + """docstring""" + # ...do stuff here... + super(MyClass, self).impl(*args, **kwargs) + +# ...do stuff here... diff --git a/pylint/test/input/func_noerror_property_affectation_py26.py b/pylint/test/input/func_noerror_property_affectation_py26.py new file mode 100644 index 0000000..d91f455 --- /dev/null +++ b/pylint/test/input/func_noerror_property_affectation_py26.py @@ -0,0 +1,24 @@ +# pylint: disable=R0903 +""" +Simple test case for an annoying behavior in pylint. +""" + +__revision__ = 'pouet' + +class Test(object): + """Smallest test case for reported issue.""" + + def __init__(self): + self._thing = None + + @property + def myattr(self): + """Getter for myattr""" + return self._thing + + @myattr.setter + def myattr(self, value): + """Setter for myattr.""" + self._thing = value + +Test().myattr = 'grou' diff --git a/pylint/test/input/func_noerror_raise_return_self.py b/pylint/test/input/func_noerror_raise_return_self.py new file mode 100644 index 0000000..2834c3c --- /dev/null +++ b/pylint/test/input/func_noerror_raise_return_self.py @@ -0,0 +1,15 @@ +"""see ticket #5672""" +# pylint: disable=R0903,W0232,C0111,C0103 + +__revision__ = 0 + +class MultiException(Exception): + def __init__(self): + Exception.__init__(self) + def return_self(self): + return self + +# raise Exception +if 1: + raise MultiException().return_self() + diff --git a/pylint/test/input/func_noerror_socket_member.py b/pylint/test/input/func_noerror_socket_member.py new file mode 100644 index 0000000..1cdafe6 --- /dev/null +++ b/pylint/test/input/func_noerror_socket_member.py @@ -0,0 +1,25 @@ +"""Testing Pylint with the socket module + +Pylint Problem +============== + +Version used: + + - Pylint 0.10.0 + - Logilab common 0.15.0 + - Logilab astroid 0.15.1 + +False E1101 positive, line 23: + + Instance of '_socketobject' has no 'connect' member + +""" +from __future__ import absolute_import +__revision__ = None +import socket + +if __name__ == "__main__": + + SCKT = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + SCKT.connect(('127.0.0.1', 80)) + SCKT.close() diff --git a/pylint/test/input/func_noerror_static_method.py b/pylint/test/input/func_noerror_static_method.py new file mode 100644 index 0000000..ef21cb9 --- /dev/null +++ b/pylint/test/input/func_noerror_static_method.py @@ -0,0 +1,27 @@ +"""Checks if static / class methods works fine in Pylint +""" +from __future__ import print_function +__revision__ = '' + +class MyClass(object): + """doc + """ + def __init__(self): + pass + + def static_met(var1, var2): + """This is a static method + """ + print(var1, var2) + + def class_met(cls, var1): + """This is a class method + """ + print(cls, var1) + + static_met = staticmethod(static_met) + class_met = classmethod(class_met) + +if __name__ == '__main__': + MyClass.static_met("var1", "var2") + MyClass.class_met("var1") diff --git a/pylint/test/input/func_noerror_staticmethod_as_decorator_py24.py b/pylint/test/input/func_noerror_staticmethod_as_decorator_py24.py new file mode 100644 index 0000000..7884cbd --- /dev/null +++ b/pylint/test/input/func_noerror_staticmethod_as_decorator_py24.py @@ -0,0 +1,33 @@ +# pylint: disable=R0903, print-statement +"""test staticmethod and classmethod as decorator""" + +__revision__ = None + +class StaticMethod1(object): + """staticmethod test""" + def __init__(self): + pass + + @staticmethod + def do_work(): + "Working..." + + @staticmethod + def do_work_with_arg(job): + "Working on something" + print "Working on %s..." % job + + +class ClassMethod2(object): + """classmethod test""" + def __init__(self): + pass + + @classmethod + def do_work(cls): + "Working..." + + @classmethod + def do_work_with_arg(cls, job): + "Working on something" + print "Working on %s..." % job diff --git a/pylint/test/input/func_noerror_super_protected.py b/pylint/test/input/func_noerror_super_protected.py new file mode 100644 index 0000000..b0961be --- /dev/null +++ b/pylint/test/input/func_noerror_super_protected.py @@ -0,0 +1,22 @@ +"""Accessing a protected method through super() is ok.""" + +# pylint: disable=missing-docstring,too-few-public-methods, print-statement + +__revision__ = None + +class Alpha(object): + + _secret = 2 + + def test(self): + print "test %s" % self + + +class Beta(Alpha): + + def test(self): + print super(Beta, self)._secret + super(Beta, self).test() + + +Beta().test() diff --git a/pylint/test/input/func_noerror_unused_variable_py30.py b/pylint/test/input/func_noerror_unused_variable_py30.py new file mode 100644 index 0000000..ffcc978 --- /dev/null +++ b/pylint/test/input/func_noerror_unused_variable_py30.py @@ -0,0 +1,14 @@ +""" Test nonlocal uses and unused-variable. """ + +__revision__ = 1 + +def test_nonlocal(): + """ Test that assigning to a nonlocal does not trigger + an 'unused-variable' warnings. + """ + attr = True + def set_value(val): + """ Set the value in a nonlocal. """ + nonlocal attr + attr = val + return set_value diff --git a/pylint/test/input/func_noerror_used_before_assignment.py b/pylint/test/input/func_noerror_used_before_assignment.py new file mode 100644 index 0000000..844ee05 --- /dev/null +++ b/pylint/test/input/func_noerror_used_before_assignment.py @@ -0,0 +1,5 @@ +# pylint: disable = line-too-long, multiple-statements, missing-module-attribute, print-statement +"""https://bitbucket.org/logilab/pylint/issue/111/false-positive-used-before-assignment-with""" + +try: raise IOError(1, "a") +except IOError, err: print err diff --git a/pylint/test/input/func_noerror_w0232.py b/pylint/test/input/func_noerror_w0232.py new file mode 100644 index 0000000..df93855 --- /dev/null +++ b/pylint/test/input/func_noerror_w0232.py @@ -0,0 +1,10 @@ +# pylint: disable=R0903,R0923 +"""check interface and exception without __init__ doesn't print warnings +""" +__revision__ = '' + +class Interface: + """interface without docstring""" + +class MyError(Exception): + """exception without docstring""" diff --git a/pylint/test/input/func_noerror_yield_assign_py25.py b/pylint/test/input/func_noerror_yield_assign_py25.py new file mode 100644 index 0000000..011634b --- /dev/null +++ b/pylint/test/input/func_noerror_yield_assign_py25.py @@ -0,0 +1,21 @@ +"""http://www.logilab.org/ticket/8771""" +# pylint: disable=print-statement +__revision__ = 2 + +def generator(): + """yield as assignment""" + yield 45 + xxxx = yield 123 + print xxxx + +def generator_fp1(seq): + """W0631 false positive""" + for val in seq: + pass + for val in seq: + yield val + +def generator_fp2(): + """E0601 false positive""" + xxxx = 12 + yield xxxx diff --git a/pylint/test/input/func_noerror_yield_return_mix.py b/pylint/test/input/func_noerror_yield_return_mix.py new file mode 100644 index 0000000..bd78633 --- /dev/null +++ b/pylint/test/input/func_noerror_yield_return_mix.py @@ -0,0 +1,7 @@ +""" module doc """ +__revision__ = None + +def somegen(): + """this kind of mix is OK""" + yield 1 + return diff --git a/pylint/test/input/func_non_iterator_returned_py30.py b/pylint/test/input/func_non_iterator_returned_py30.py new file mode 100644 index 0000000..6915768 --- /dev/null +++ b/pylint/test/input/func_non_iterator_returned_py30.py @@ -0,0 +1,52 @@ +"""Check non-iterators returned by __iter__ """ + +# pylint: disable=too-few-public-methods + +__revision__ = 0 + +class FirstGoodIterator(object): + """ yields in iterator. """ + + def __iter__(self): + for index in range(10): + yield index + +class SecondGoodIterator(object): + """ __iter__ and next """ + + def __iter__(self): + return self + + def __next__(self): # pylint: disable=no-self-use + """ Infinite iterator, but still an iterator """ + return 1 + +class ThirdGoodIterator(object): + """ Returns other iterator, not the current instance """ + + def __iter__(self): + return SecondGoodIterator() + +class FourthGoodIterator(object): + """ __iter__ returns iter(...) """ + + def __iter__(self): + return iter(range(10)) + +class FirstBadIterator(object): + """ __iter__ returns a list """ + + def __iter__(self): + return [] + +class SecondBadIterator(object): + """ __iter__ without next """ + + def __iter__(self): + return self + +class ThirdBadIterator(object): + """ __iter__ returns an instance of another non-iterator """ + + def __iter__(self): + return SecondBadIterator() diff --git a/pylint/test/input/func_non_iterator_returned_py_30.py b/pylint/test/input/func_non_iterator_returned_py_30.py new file mode 100644 index 0000000..ff75941 --- /dev/null +++ b/pylint/test/input/func_non_iterator_returned_py_30.py @@ -0,0 +1,52 @@ +"""Check non-iterators returned by __iter__ """ + +# pylint: disable=too-few-public-methods + +__revision__ = 0 + +class FirstGoodIterator(object): + """ yields in iterator. """ + + def __iter__(self): + for index in range(10): + yield index + +class SecondGoodIterator(object): + """ __iter__ and next """ + + def __iter__(self): + return self + + def next(self): # pylint: disable=no-self-use + """ Infinite iterator, but still an iterator """ + return 1 + +class ThirdGoodIterator(object): + """ Returns other iterator, not the current instance """ + + def __iter__(self): + return SecondGoodIterator() + +class FourthGoodIterator(object): + """ __iter__ returns iter(...) """ + + def __iter__(self): + return iter(range(10)) + +class FirstBadIterator(object): + """ __iter__ returns a list """ + + def __iter__(self): + return [] + +class SecondBadIterator(object): + """ __iter__ without next """ + + def __iter__(self): + return self + +class ThirdBadIterator(object): + """ __iter__ returns an instance of another non-iterator """ + + def __iter__(self): + return SecondBadIterator() diff --git a/pylint/test/input/func_nonregr___file___global.py b/pylint/test/input/func_nonregr___file___global.py new file mode 100644 index 0000000..910033c --- /dev/null +++ b/pylint/test/input/func_nonregr___file___global.py @@ -0,0 +1,8 @@ +"""test no crash on __file__ global""" + +def func(): + """override __file__""" + global __file__ + __file__ = 'hop' + +__revision__ = 'pouet' diff --git a/pylint/test/input/func_operators.py b/pylint/test/input/func_operators.py new file mode 100644 index 0000000..48606bf --- /dev/null +++ b/pylint/test/input/func_operators.py @@ -0,0 +1,19 @@ +"""check operator use""" +#pylint: disable=C0103 +#pylint: disable=W0104 + +__revision__ = 42 + +a = 1 +a += 5 +a = +a +b = ++a +++a +c = (++a) * b + +a = 1 +a -= 5 +b = --a +b = a +--a +c = (--a) * b diff --git a/pylint/test/input/func_r0901.py b/pylint/test/input/func_r0901.py new file mode 100644 index 0000000..ac69fb6 --- /dev/null +++ b/pylint/test/input/func_r0901.py @@ -0,0 +1,27 @@ +# pylint: disable=W0232, R0903 +"""test max parents""" +__revision__ = None + +class Aaaa(object): + """yo""" +class Bbbb(object): + """yo""" +class Cccc(object): + """yo""" +class Dddd(object): + """yo""" +class Eeee(object): + """yo""" +class Ffff(object): + """yo""" +class Gggg(object): + """yo""" +class Hhhh(object): + """yo""" + +class Iiii(Aaaa, Bbbb, Cccc, Dddd, Eeee, Ffff, Gggg, Hhhh): + """yo""" + +class Jjjj(Iiii): + """yo""" + diff --git a/pylint/test/input/func_r0902.py b/pylint/test/input/func_r0902.py new file mode 100644 index 0000000..d0a7483 --- /dev/null +++ b/pylint/test/input/func_r0902.py @@ -0,0 +1,28 @@ +# pylint: disable=R0903 +"""test max instance attributes""" +__revision__ = None + +class Aaaa(object): + """yo""" + def __init__(self): + self.aaaa = 1 + self.bbbb = 2 + self.cccc = 3 + self.dddd = 4 + self.eeee = 5 + self.ffff = 6 + self.gggg = 7 + self.hhhh = 8 + self.iiii = 9 + self.jjjj = 10 + self._aaaa = 1 + self._bbbb = 2 + self._cccc = 3 + self._dddd = 4 + self._eeee = 5 + self._ffff = 6 + self._gggg = 7 + self._hhhh = 8 + self._iiii = 9 + self._jjjj = 10 + self.tomuch = None diff --git a/pylint/test/input/func_r0903.py b/pylint/test/input/func_r0903.py new file mode 100644 index 0000000..49008f9 --- /dev/null +++ b/pylint/test/input/func_r0903.py @@ -0,0 +1,30 @@ +"""test min methods""" +from __future__ import print_function +__revision__ = None + +class Aaaa(object): + """yo""" + def __init__(self): + pass + def meth1(self): + """hehehe""" + print(self) + def _dontcount(self): + """not public""" + print(self) + + +# Don't emit for these cases. +class Klass(object): + """docstring""" + + def meth1(self): + """first""" + + def meth2(self): + """second""" + + +class EnoughPublicMethods(Klass): + """We shouldn't emit too-few-public-methods for this.""" + diff --git a/pylint/test/input/func_r0904.py b/pylint/test/input/func_r0904.py new file mode 100644 index 0000000..85daf61 --- /dev/null +++ b/pylint/test/input/func_r0904.py @@ -0,0 +1,80 @@ +# pylint: disable=R0201 +"""test max methods""" +__revision__ = None +class Aaaa(object): + """yo""" + def __init__(self): + pass + + def meth1(self): + """hehehe""" + + def meth2(self): + """hehehe""" + + def meth3(self): + """hehehe""" + + def meth4(self): + """hehehe""" + + def meth5(self): + """hehehe""" + + def meth6(self): + """hehehe""" + + def meth7(self): + """hehehe""" + + def meth8(self): + """hehehe""" + + def meth9(self): + """hehehe""" + + def meth10(self): + """hehehe""" + + def meth11(self): + """hehehe""" + + def meth12(self): + """hehehe""" + + def meth13(self): + """hehehe""" + + def meth14(self): + """hehehe""" + + def meth15(self): + """hehehe""" + + def meth16(self): + """hehehe""" + + def meth17(self): + """hehehe""" + + def meth18(self): + """hehehe""" + + def meth19(self): + """hehehe""" + + def meth20(self): + """hehehe""" + + def meth21(self): + """hehehe""" + + def _dontcount(self): + """not public""" + +class BBB(Aaaa): + """Don't emit for methods defined in the parent.""" + def meth1(self): + """trop""" + def meth2(self): + """tzop""" diff --git a/pylint/test/input/func_r0921.py b/pylint/test/input/func_r0921.py new file mode 100644 index 0000000..1baf0a8 --- /dev/null +++ b/pylint/test/input/func_r0921.py @@ -0,0 +1,15 @@ +"""test max methods""" +__revision__ = None + +class Aaaa(object): + """yo""" + def __init__(self): + pass + + def meth1(self): + """hehehe""" + raise NotImplementedError + + def meth2(self): + """hehehe""" + return 'Yo', self diff --git a/pylint/test/input/func_r0922.py b/pylint/test/input/func_r0922.py new file mode 100644 index 0000000..705ef3a --- /dev/null +++ b/pylint/test/input/func_r0922.py @@ -0,0 +1,21 @@ +"""test max methods""" +__revision__ = None +# pylint: disable=too-few-public-methods +class Aaaa(object): + """yo""" + def __init__(self): + pass + + def meth1(self): + """hehehe""" + raise NotImplementedError + + def meth2(self): + """hehehe""" + return 'Yo', self + +class Bbbb(Aaaa): + """yeah""" + def meth1(self): + """hehehe bis""" + return "yeah", self diff --git a/pylint/test/input/func_r0923.py b/pylint/test/input/func_r0923.py new file mode 100644 index 0000000..8ab44a1 --- /dev/null +++ b/pylint/test/input/func_r0923.py @@ -0,0 +1,31 @@ +"""test max methods""" +from __future__ import absolute_import +__revision__ = None +from logilab.common.interface import Interface + +class IAaaa(Interface): + """yo""" + + def meth1(self): + """hehehe""" + +class IBbbb(Interface): + """yo""" + + def meth1(self): + """hehehe""" + +class Concret(object): + """implements IBbbb""" + __implements__ = IBbbb + + def __init__(self): + pass + + def meth1(self): + """hehehe""" + return "et hop", self + + def meth2(self): + """hehehe""" + return "et hop", self diff --git a/pylint/test/input/func_reqattrs.py b/pylint/test/input/func_reqattrs.py new file mode 100644 index 0000000..fb1e2b6 --- /dev/null +++ b/pylint/test/input/func_reqattrs.py @@ -0,0 +1 @@ +"""docstring""" diff --git a/pylint/test/input/func_return_outside_func.py b/pylint/test/input/func_return_outside_func.py new file mode 100644 index 0000000..440798d --- /dev/null +++ b/pylint/test/input/func_return_outside_func.py @@ -0,0 +1,3 @@ +"""This is gramatically correct, but it's still a SyntaxError""" +__revision__ = None +return diff --git a/pylint/test/input/func_return_yield_mix_py_33.py b/pylint/test/input/func_return_yield_mix_py_33.py new file mode 100644 index 0000000..1a3cd5d --- /dev/null +++ b/pylint/test/input/func_return_yield_mix_py_33.py @@ -0,0 +1,16 @@ +"""pylint should detect yield and return mix inside genrators""" +__revision__ = None +def somegen(): + """this is a bad generator""" + if True: + return 1 + else: + yield 2 + +def moregen(): + """this is another bad generator""" + if True: + yield 1 + else: + return 2 + diff --git a/pylint/test/input/func_set_literal_as_default_py27.py b/pylint/test/input/func_set_literal_as_default_py27.py new file mode 100644 index 0000000..1bd3f7e --- /dev/null +++ b/pylint/test/input/func_set_literal_as_default_py27.py @@ -0,0 +1,7 @@ +"""docstring""" +from __future__ import print_function +__revision__ = '' + +def function1(value={1}): + """set is mutable and dangerous.""" + print(value) diff --git a/pylint/test/input/func_syntax_error.py b/pylint/test/input/func_syntax_error.py new file mode 100644 index 0000000..43fa087 --- /dev/null +++ b/pylint/test/input/func_syntax_error.py @@ -0,0 +1 @@ +def toto diff --git a/pylint/test/input/func_tokenize_error.py b/pylint/test/input/func_tokenize_error.py new file mode 100644 index 0000000..1b52cb9 --- /dev/null +++ b/pylint/test/input/func_tokenize_error.py @@ -0,0 +1,6 @@ +"""A module that is accepted by Python but rejected by tokenize. + +The problem is the trailing line continuation at the end of the line, +which produces a TokenError.""" + +""\ diff --git a/pylint/test/input/func_too_many_locals_arguments.py b/pylint/test/input/func_too_many_locals_arguments.py new file mode 100644 index 0000000..f63a5ee --- /dev/null +++ b/pylint/test/input/func_too_many_locals_arguments.py @@ -0,0 +1,52 @@ +"""tests number of arguments and local variables in functions +""" + +__revision__ = None + +def too_many_locals_function(): + '''pylint will complains about too many local variables''' + args0 = 0 + args1 = args0 * 1 + args2 = args1 * 2 + args3 = args2 * 3 + args4 = args3 * 4 + args5 = args4 * 5 + args6 = args5 * 6 + args7 = args6 * 7 + args8 = args7 * 8 + args9 = args8 * 9 + args10 = args9 * 10 + args11 = args10 * 11 + args12 = args11 * 12 + args13 = args12 * 13 + args14 = args13 * 14 + args15 = args14 * 15 + return args15 + +def too_many_arguments_function(arga, argu, argi, arge, argt, args): + '''pylint will complains about too many arguments.''' + arga = argu + arga += argi + arga += arge + arga += argt + arga += args + return arga + +def ignored_arguments_function(arga, argu, argi, + _arge=0, _argt=1, _args=None): + '''pylint will ignore _arge, _argt, _args. + Consequently pylint will only coun 13 arguments''' + arg0 = 0 + arg1 = arg0 * 1 + arga + arg2 = arg1 * 2 + argu + arg3 = arg2 * 3 + argi + arg4 = arg3 * 4 + _arge + arg5 = arg4 * 5 + _argt + arg6 = arg5 * 6 + arg7 = arg6 * 7 + arg8 = arg7 * 8 + arg9 = arg8 * 9 + arg9 += arg0 + if _args: + arg9 += sum(_args) + return arg9 diff --git a/pylint/test/input/func_too_many_returns_yields.py b/pylint/test/input/func_too_many_returns_yields.py new file mode 100644 index 0000000..c61bd7d --- /dev/null +++ b/pylint/test/input/func_too_many_returns_yields.py @@ -0,0 +1,42 @@ +"""test""" + +__revision__ = None + +def too_many_returns(arg): + """is this real ?""" + if arg == 1: + return 1 + elif arg == 2: + return 2 + elif arg == 3: + return 3 + elif arg == 4: + return 4 + elif arg == 5: + return 5 + elif arg == 6: + return 6 + elif arg == 7: + return 7 + elif arg == 8: + return 8 + elif arg == 9: + return 9 + elif arg == 10: + return 10 + return None + +def many_yield(text): + """not a problem""" + if text: + yield " line 1: %s\n" % text + yield " line 2\n" + yield " line 3\n" + yield " line 4\n" + yield " line 5\n" + else: + yield " line 6\n" + yield " line 7\n" + yield " line 8\n" + yield " line 9\n" + yield " line 10\n" diff --git a/pylint/test/input/func_toolonglines.py b/pylint/test/input/func_toolonglines.py new file mode 100644 index 0000000..272395f --- /dev/null +++ b/pylint/test/input/func_toolonglines.py @@ -0,0 +1,27 @@ +##################################################################################################### +""" that one is too long tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo loooooong""" + +__revision__ = '' + +# The next line is exactly 80 characters long. +A = '--------------------------------------------------------------------------' + +# The next line is longer than 80 characters, because the file is encoded +# in ASCII. +THIS_IS_A_VERY_LONG_VARIABLE_NAME = 'СущеÑтвительное ЧаÑтица' # With warnings. + +# Do not trigger the line-too-long warning if the only token that makes the +# line longer than 80 characters is a trailing pylint disable. +var = 'This line has a disable pragma and whitespace trailing beyond 80 chars. ' # pylint:disable=invalid-name + +badname = 'This line is already longer than 100 characters even without the pragma. Trust me. Please.' # pylint:disable=invalid-name + +# http://example.com/this/is/a/very/long/url?but=splitting&urls=is&a=pain&so=they&can=be&long + + +def function(): + """This is a docstring. + + That contains a very, very long line that exceeds the 100 characters limit by a good margin. So good? + """ + pass diff --git a/pylint/test/input/func_trailing_whitespace.py b/pylint/test/input/func_trailing_whitespace.py new file mode 100644 index 0000000..946d748 --- /dev/null +++ b/pylint/test/input/func_trailing_whitespace.py @@ -0,0 +1,8 @@ +"""Regression test for trailing-whitespace (C0303).""" +# pylint: disable=mixed-line-endings, print-statement +__revision__ = 0 + +print 'some trailing whitespace' +print 'trailing whitespace does not count towards the line length limit' +print 'windows line ends are ok'
+print 'but trailing whitespace on win is not'
diff --git a/pylint/test/input/func_typecheck_callfunc_assigment.py b/pylint/test/input/func_typecheck_callfunc_assigment.py new file mode 100644 index 0000000..3a668ab --- /dev/null +++ b/pylint/test/input/func_typecheck_callfunc_assigment.py @@ -0,0 +1,63 @@ +# pylint: disable=R0921, print-statement +"""check assignment to function call where the function doesn't return + + 'E1111': ('Assigning to function call which doesn\'t return', + 'Used when an assignment is done on a function call but the \ + infered function doesn\'t return anything.'), + 'W1111': ('Assigning to function call which only returns None', + 'Used when an assignment is done on a function call but the \ + infered function returns nothing but None.'), + +""" +from __future__ import generators +__revision__ = None + + +def func_no_return(): + """function without return""" + print 'dougloup' + +A = func_no_return() + + +def func_return_none(): + """function returning none""" + print 'dougloup' + return None + +A = func_return_none() + + +def func_implicit_return_none(): + """Function returning None from bare return statement.""" + return + +A = func_implicit_return_none() + + +def func_return_none_and_smth(): + """function returning none and something else""" + print 'dougloup' + if __revision__: + return None + return 3 + +A = func_return_none_and_smth() + +def generator(): + """no problemo""" + yield __revision__ + +A = generator() + +class Abstract(object): + """bla bla""" + + def abstract_method(self): + """use to return something in concrete implementation""" + raise NotImplementedError + + def use_abstract(self): + """should not issue E1111""" + var = self.abstract_method() + print var diff --git a/pylint/test/input/func_typecheck_non_callable_call.py b/pylint/test/input/func_typecheck_non_callable_call.py new file mode 100644 index 0000000..832657d --- /dev/null +++ b/pylint/test/input/func_typecheck_non_callable_call.py @@ -0,0 +1,118 @@ +# pylint: disable=R0903,missing-docstring,no-self-use +""" + 'E1102': ('%s is not callable', + 'Used when an object being called has been infered to a non \ + callable object'), +""" + +__revision__ = None + +__revision__() + +def correct(): + """callable object""" + return 1 + +__revision__ = correct() + +class Correct(object): + """callable object""" + +class MetaCorrect(object): + """callable object""" + def __call__(self): + return self + +INSTANCE = Correct() +CALLABLE_INSTANCE = MetaCorrect() +CORRECT = CALLABLE_INSTANCE() +INCORRECT = INSTANCE() +LIST = [] +INCORRECT = LIST() +DICT = {} +INCORRECT = DICT() +TUPLE = () +INCORRECT = TUPLE() +INT = 1 +INCORRECT = INT() + +# Test calling properties. Pylint can detect when using only the +# getter, but it doesn't infer properly when having a getter +# and a setter. +class MyProperty(property): + """ test subclasses """ + +class PropertyTest(object): + """ class """ + + def __init__(self): + self.attr = 4 + + @property + def test(self): + """ Get the attribute """ + return self.attr + + @test.setter + def test(self, value): + """ Set the attribute """ + self.attr = value + + @MyProperty + def custom(self): + """ Get the attribute """ + return self.attr + + @custom.setter + def custom(self, value): + """ Set the attribute """ + self.attr = value + +PROP = PropertyTest() +PROP.test(40) +PROP.custom() + +# Safe from not-callable when using properties. + +class SafeProperty(object): + @property + def static(self): + return staticmethod + + @property + def klass(self): + return classmethod + + @property + def get_lambda(self): + return lambda: None + + @property + def other_function(self): + def function(arg): + return arg + return function + + @property + def dict_builtin(self): + return dict + + @property + def range_builtin(self): + return range + + @property + def instance(self): + class Empty(object): + def __call__(self): + return 42 + return Empty() + +PROP1 = SafeProperty() +PROP1.static(2) +PROP1.klass(2) +PROP1.get_lambda() +PROP1.other_function(4) +PROP1.dict_builtin() +PROP1.range_builtin(4) +PROP1.instance() diff --git a/pylint/test/input/func_undefined_metaclass_var_py30.py b/pylint/test/input/func_undefined_metaclass_var_py30.py new file mode 100644 index 0000000..307a431 --- /dev/null +++ b/pylint/test/input/func_undefined_metaclass_var_py30.py @@ -0,0 +1,27 @@ +"""test access to undefined variables in Python 3 metaclass syntax """ +# pylint: disable=no-init, invalid-name, too-few-public-methods +__revision__ = '$Id:' + +import abc +from abc import ABCMeta + +class Bad(metaclass=ABCMet): + """ Notice the typo """ + +class SecondBad(metaclass=ab.ABCMeta): + """ Notice the `ab` module. """ + +class Good(metaclass=int): + """ int is not a proper metaclass, but it is defined. """ + +class SecondGood(metaclass=Good): + """ empty """ + +class ThirdGood(metaclass=ABCMeta): + """ empty """ + +class FourthGood(ThirdGood): + """ This should not trigger anything. """ + +data = abc +testdata = ABCMeta diff --git a/pylint/test/input/func_unreachable.py b/pylint/test/input/func_unreachable.py new file mode 100644 index 0000000..4034e4f --- /dev/null +++ b/pylint/test/input/func_unreachable.py @@ -0,0 +1,21 @@ +"""docstring""" +from __future__ import print_function +__revision__ = '' + +def func1(): + """docstring""" + return 1 + print('unreachable') + +def func2(): + """docstring""" + while 1: + break + print('unreachable') + +def func3(): + """docstring""" + for i in (1, 2, 3): + print(i) + continue + print('unreachable') diff --git a/pylint/test/input/func_unused_import_py30.py b/pylint/test/input/func_unused_import_py30.py new file mode 100644 index 0000000..d7a38c5 --- /dev/null +++ b/pylint/test/input/func_unused_import_py30.py @@ -0,0 +1,21 @@ +"""check unused import for metaclasses +""" +# pylint: disable=too-few-public-methods +__revision__ = 1 +import abc +import sys +from abc import ABCMeta +from abc import ABCMeta as SomethingElse + +class Meta(metaclass=abc.ABCMeta): + """ Test """ + def __init__(self): + self.data = sys.executable + self.test = abc + +class Meta2(metaclass=ABCMeta): + """ Test """ + +class Meta3(metaclass=SomethingElse): + """ test """ + diff --git a/pylint/test/input/func_unused_overridden_argument.py b/pylint/test/input/func_unused_overridden_argument.py new file mode 100644 index 0000000..85430d4 --- /dev/null +++ b/pylint/test/input/func_unused_overridden_argument.py @@ -0,0 +1,31 @@ +# pylint: disable=R0903, print-statement +"""for Sub.inherited, only the warning for "aay" is desired. +The warnings for "aab" and "aac" are most likely false positives though, +because there could be another subclass that overrides the same method and does +use the arguments (eg Sub2) +""" + +__revision__ = 'thx to Maarten ter Huurne' + +class Base(object): + "parent" + def inherited(self, aaa, aab, aac): + "abstract method" + raise NotImplementedError + +class Sub(Base): + "child 1" + def inherited(self, aaa, aab, aac): + "overridden method, though don't use every argument" + return aaa + + def newmethod(self, aax, aay): + "another method, warning for aay desired" + print self, aax + +class Sub2(Base): + "child 1" + + def inherited(self, aaa, aab, aac): + "overridden method, use every argument" + return aaa + aab + aac diff --git a/pylint/test/input/func_use_for_or_listcomp_var.py b/pylint/test/input/func_use_for_or_listcomp_var.py new file mode 100644 index 0000000..5690a2c --- /dev/null +++ b/pylint/test/input/func_use_for_or_listcomp_var.py @@ -0,0 +1,27 @@ +"""test a warning is triggered when using for a lists comprehension variable""" +# pylint: disable=print-statement +__revision__ = 'yo' + +TEST_LC = [C for C in __revision__ if C.isalpha()] +print C # WARN +C = 4 +print C # this one shouldn't trigger any warning + +B = [B for B in __revision__ if B.isalpha()] +print B # nor this one + +for var1, var2 in TEST_LC: + var1 = var2 + 4 +print var1 # WARN + +for note in __revision__: + note.something() +for line in __revision__: + for note in line: + A = note.anotherthing() + + +for x in []: + pass +for x in range(3): + print (lambda: x)() # OK diff --git a/pylint/test/input/func_used_before_assignment_py30.py b/pylint/test/input/func_used_before_assignment_py30.py new file mode 100644 index 0000000..ae979a1 --- /dev/null +++ b/pylint/test/input/func_used_before_assignment_py30.py @@ -0,0 +1,48 @@ +"""Check for nonlocal and used-before-assignment"""
+# pylint: disable=missing-docstring, unused-variable, no-init, too-few-public-methods
+
+__revision__ = 0
+
+def test_ok():
+ """ uses nonlocal """
+ cnt = 1
+ def wrap():
+ nonlocal cnt
+ cnt = cnt + 1
+ wrap()
+
+def test_fail():
+ """ doesn't use nonlocal """
+ cnt = 1
+ def wrap():
+ cnt = cnt + 1
+ wrap()
+
+def test_fail2():
+ """ use nonlocal, but for other variable """
+ cnt = 1
+ count = 1
+ def wrap():
+ nonlocal count
+ cnt = cnt + 1
+ wrap()
+
+def test_fail3(arg: test_fail4):
+ """ Depends on `test_fail4`, in argument annotation. """
+ return arg
+
+def test_fail4(*args: test_fail5, **kwargs: undefined):
+ """ Depends on `test_fail5` and `undefined` in
+ variable and named arguments annotations.
+ """
+ return args, kwargs
+
+def test_fail5()->undefined1:
+ """ Depends on `undefined1` in function return annotation. """
+
+def undefined():
+ """ no op """
+
+def undefined1():
+ """ no op """
+
diff --git a/pylint/test/input/func_variables_unused_name_from_wilcard_import.py b/pylint/test/input/func_variables_unused_name_from_wilcard_import.py new file mode 100644 index 0000000..e5763ad --- /dev/null +++ b/pylint/test/input/func_variables_unused_name_from_wilcard_import.py @@ -0,0 +1,4 @@ +"""check unused import from a wildcard import""" +# pylint: disable=no-absolute-import +from input.func_w0611 import * +__revision__ = None diff --git a/pylint/test/input/func_w0101.py b/pylint/test/input/func_w0101.py new file mode 100644 index 0000000..fe543aa --- /dev/null +++ b/pylint/test/input/func_w0101.py @@ -0,0 +1,28 @@ +"""test max returns +""" + +__revision__ = '' + +def stupid_function(arg): + """reallly stupid function""" + if arg == 1: + return 1 + elif arg == 2: + return 2 + elif arg == 3: + return 3 + elif arg == 4: + return 4 + elif arg == 5: + return 5 + elif arg == 6: + return 6 + elif arg == 7: + return 7 + elif arg == 8: + return 8 + elif arg == 9: + return 9 + elif arg == 10: + return 10 + return None diff --git a/pylint/test/input/func_w0102.py b/pylint/test/input/func_w0102.py new file mode 100644 index 0000000..8a8ae4d --- /dev/null +++ b/pylint/test/input/func_w0102.py @@ -0,0 +1,67 @@ +# pylint: disable=R0201 +"""docstring""" +__revision__ = '' + +class AAAA(object): + """docstring""" + def __init__(self): + pass + def method1(self): + """docstring""" + + def method2(self): + """docstring""" + + def method2(self): + """docstring""" + +class AAAA(object): + """docstring""" + def __init__(self): + pass + def yeah(self): + """hehehe""" + def yoo(self): + """yoo""" +def func1(): + """docstring""" + +def func2(): + """docstring""" + +def func2(): + """docstring""" + __revision__ = 1 + return __revision__ + +if __revision__: + def exclusive_func(): + "docstring" +else: + def exclusive_func(): + "docstring" + +try: + def exclusive_func2(): + "docstring" +except TypeError: + def exclusive_func2(): + "docstring" +else: + def exclusive_func2(): + "this one redefine the one defined line 42" + + +def with_inner_function_1(): + """docstring""" + def callback(): + """callback docstring""" + pass + return callback + +def with_inner_function_2(): + """docstring""" + def callback(): + """does not redefine callback returned by with_inner_function_1""" + pass + return callback diff --git a/pylint/test/input/func_w0103.py b/pylint/test/input/func_w0103.py new file mode 100644 index 0000000..04cb4c1 --- /dev/null +++ b/pylint/test/input/func_w0103.py @@ -0,0 +1,8 @@ +"""test max branch +""" +from __future__ import print_function +__revision__ = '' + +def stupid_function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9): + """reallly stupid function""" + print(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) diff --git a/pylint/test/input/func_w0104.py b/pylint/test/input/func_w0104.py new file mode 100644 index 0000000..6588e98 --- /dev/null +++ b/pylint/test/input/func_w0104.py @@ -0,0 +1,12 @@ +"""test max branch +""" +# pylint: disable=print-statement +__revision__ = '' + +def stupid_function(arg1, arg2, arg3, arg4, arg5): + """reallly stupid function""" + arg6, arg7, arg8, arg9 = arg1, arg2, arg3, arg4 + print arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 + loc1, loc2, loc3, loc4, loc5, loc6, loc7 = arg1, arg2, arg3, arg4, arg5, \ + arg6, arg7 + print loc1, loc2, loc3, loc4, loc5, loc6, loc7 diff --git a/pylint/test/input/func_w0105.py b/pylint/test/input/func_w0105.py new file mode 100644 index 0000000..c40870e --- /dev/null +++ b/pylint/test/input/func_w0105.py @@ -0,0 +1,62 @@ +"""test max branch +""" +# pylint: disable=print-statement +__revision__ = '' + +def stupid_function(arg): + """reallly stupid function""" + if arg == 1: + print 1 + elif arg == 2: + print 2 + elif arg == 3: + print 3 + elif arg == 4: + print 4 + elif arg == 5: + print 5 + elif arg == 6: + print 6 + elif arg == 7: + print 7 + elif arg == 8: + print 8 + elif arg == 9: + print 9 + elif arg == 10: + print 10 + elif arg < 1: + print 0 + print 100 + arg = 0 + for val in range(arg): + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val + print val diff --git a/pylint/test/input/func_w0110.py b/pylint/test/input/func_w0110.py new file mode 100644 index 0000000..c9d9311 --- /dev/null +++ b/pylint/test/input/func_w0110.py @@ -0,0 +1,10 @@ +"""test too short name +""" + +__revision__ = 1 + +A = None + +def a(): + """yo""" + pass diff --git a/pylint/test/input/func_w0111.py b/pylint/test/input/func_w0111.py new file mode 100644 index 0000000..f8ad440 --- /dev/null +++ b/pylint/test/input/func_w0111.py @@ -0,0 +1,10 @@ +"""test black listed name +""" + +__revision__ = 1 + +A = None + +def baz(): + """yo""" + pass diff --git a/pylint/test/input/func_w0112.py b/pylint/test/input/func_w0112.py new file mode 100644 index 0000000..6bddf00 --- /dev/null +++ b/pylint/test/input/func_w0112.py @@ -0,0 +1,37 @@ +"""test max branch +""" +# pylint: disable=print-statement +__revision__ = '' + +def stupid_function(arg): + """reallly stupid function""" + if arg == 1: + print 1 + elif arg == 2: + print 2 + elif arg == 3: + print 3 + elif arg == 4: + print 4 + elif arg == 5: + print 5 + elif arg == 6: + print 6 + elif arg == 7: + print 7 + elif arg == 8: + print 8 + elif arg == 9: + print 9 + elif arg == 10: + print 10 + else: + if arg < 1: + print 0 + else: + print 100 + arg = 0 + if arg: + print None + else: + print arg diff --git a/pylint/test/input/func_w0122_py_30.py b/pylint/test/input/func_w0122_py_30.py new file mode 100644 index 0000000..178c252 --- /dev/null +++ b/pylint/test/input/func_w0122_py_30.py @@ -0,0 +1,13 @@ +"""test global statement""" + +__revision__ = 0 + +exec 'a = __revision__' +exec 'a = 1' in {} + +exec 'a = 1' in globals() + +def func(): + """exec in local scope""" + exec 'b = 1' + diff --git a/pylint/test/input/func_w0151.py b/pylint/test/input/func_w0151.py new file mode 100644 index 0000000..e6862c5 --- /dev/null +++ b/pylint/test/input/func_w0151.py @@ -0,0 +1,5 @@ +"""check black listed builtins +""" + +__revision__ = map(str, (1, 2, 3)) + diff --git a/pylint/test/input/func_w0152.py b/pylint/test/input/func_w0152.py new file mode 100644 index 0000000..9fff4a6 --- /dev/null +++ b/pylint/test/input/func_w0152.py @@ -0,0 +1,18 @@ +"""check use of * or ** +""" +# pylint: disable=no-absolute-import +from operator import add +__revision__ = reduce(*(add, (1, 2, 3))) + + +def func(arg1, arg2): + """magic function + """ + return arg2, arg1 + +MYDICT = {'arg1':2, 'arg2': 4} +func(**MYDICT) + +def coolfunc(*args, **kwargs): + """magic function""" + return func(*args, **kwargs) diff --git a/pylint/test/input/func_w0202.py b/pylint/test/input/func_w0202.py new file mode 100644 index 0000000..00b5b0f --- /dev/null +++ b/pylint/test/input/func_w0202.py @@ -0,0 +1,17 @@ +"""check static method with self or cls as first argument""" + +__revision__ = None + +class Abcd(object): + """dummy""" + + def method1(self): + """hehe""" + method1 = staticmethod(method1) + + def method2(cls): + """hehe""" + method2 = staticmethod(method2) + + def __init__(self): + pass diff --git a/pylint/test/input/func_w0205.py b/pylint/test/input/func_w0205.py new file mode 100644 index 0000000..896be6c --- /dev/null +++ b/pylint/test/input/func_w0205.py @@ -0,0 +1,24 @@ +"""check different signatures""" +from __future__ import print_function +__revision__ = 0 +# pylint: disable=too-few-public-methods +class Abcd(object): + '''dummy''' + def __init__(self): + self.aarg = False + def abcd(self, aaa=1, bbbb=None): + """hehehe""" + print(self, aaa, bbbb) + def args(self): + """gaarrrggll""" + self.aarg = True + +class Cdef(Abcd): + """dummy""" + def __init__(self, aaa): + Abcd.__init__(self) + self.aaa = aaa + + def abcd(self, aaa, bbbb=None): + """hehehe""" + print(self, aaa, bbbb) diff --git a/pylint/test/input/func_w0233.py b/pylint/test/input/func_w0233.py new file mode 100644 index 0000000..fe679bb --- /dev/null +++ b/pylint/test/input/func_w0233.py @@ -0,0 +1,50 @@ +# pylint: disable=R0903,W0212,W0403,W0406,no-absolute-import +"""test for call to __init__ from a non ancestor class +""" +from __future__ import print_function +__revision__ = '$Id: func_w0233.py,v 1.2 2004-09-29 08:35:13 syt Exp $' + +class AAAA(object): + """ancestor 1""" + + def __init__(self): + print('init', self) + BBBBMixin.__init__(self) + +class BBBBMixin(object): + """ancestor 2""" + + def __init__(self): + print('init', self) + +import nonexistant +import func_w0233 +class CCC(BBBBMixin, func_w0233.AAAA, func_w0233.BBBB, nonexistant.AClass): + """mix different things, some inferable some not""" + def __init__(self): + BBBBMixin.__init__(self) + func_w0233.AAAA.__init__(self) + func_w0233.BBBB.__init__(self) + nonexistant.AClass.__init__(self) + +class DDDD(AAAA): + """call superclass constructor in disjunct branches""" + def __init__(self, value): + if value: + AAAA.__init__(self) + else: + AAAA.__init__(self) + +class Super(dict): + """ test late binding super() call """ + def __init__(self): + base = super() + base.__init__() + +class Super2(dict): + """ Using the same idiom as Super, but without calling + the __init__ method. + """ + def __init__(self): + base = super() + base.__woohoo__() diff --git a/pylint/test/input/func_w0302.py b/pylint/test/input/func_w0302.py new file mode 100644 index 0000000..a78f479 --- /dev/null +++ b/pylint/test/input/func_w0302.py @@ -0,0 +1,1016 @@ +"""test too much line in modules +""" + +__revision__ = 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +ZERFZAER = 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +HEHEHE = 2 diff --git a/pylint/test/input/func_w0312.py b/pylint/test/input/func_w0312.py new file mode 100644 index 0000000..491f75b --- /dev/null +++ b/pylint/test/input/func_w0312.py @@ -0,0 +1,11 @@ +"""test mixed tabs and spaces""" +from __future__ import print_function +__revision__ = 1 + +def spaces_func(): + """yo""" + print("yo") + +def tab_func(): + """yo""" + print("yo") diff --git a/pylint/test/input/func_w0332_py_30.py b/pylint/test/input/func_w0332_py_30.py new file mode 100644 index 0000000..6a38e8c --- /dev/null +++ b/pylint/test/input/func_w0332_py_30.py @@ -0,0 +1,4 @@ +"""check use of l as long int marker +""" +# pylint: disable=long-suffix +__revision__ = 1l diff --git a/pylint/test/input/func_w0401.py b/pylint/test/input/func_w0401.py new file mode 100644 index 0000000..caf59c9 --- /dev/null +++ b/pylint/test/input/func_w0401.py @@ -0,0 +1,9 @@ +"""test cyclic import +""" +# pylint: disable=print-statement, no-absolute-import +__revision__ = 0 + +from input import w0401_cycle + +if __revision__: + print w0401_cycle diff --git a/pylint/test/input/func_w0401_package/__init__.py b/pylint/test/input/func_w0401_package/__init__.py new file mode 100644 index 0000000..dedef66 --- /dev/null +++ b/pylint/test/input/func_w0401_package/__init__.py @@ -0,0 +1,2 @@ +"""Our big package.""" +__revision__ = None diff --git a/pylint/test/input/func_w0401_package/all_the_things.py b/pylint/test/input/func_w0401_package/all_the_things.py new file mode 100644 index 0000000..67a627e --- /dev/null +++ b/pylint/test/input/func_w0401_package/all_the_things.py @@ -0,0 +1,9 @@ +"""All the things!""" +# pylint: disable=no-absolute-import +__revision__ = None +from .thing1 import THING1 +from .thing2 import THING2 +from .thing2 import THING1_PLUS_THING2 + +_ = (THING1, THING2, THING1_PLUS_THING2) +del _ diff --git a/pylint/test/input/func_w0401_package/thing1.py b/pylint/test/input/func_w0401_package/thing1.py new file mode 100644 index 0000000..34972a7 --- /dev/null +++ b/pylint/test/input/func_w0401_package/thing1.py @@ -0,0 +1,3 @@ +"""The first thing.""" +__revision__ = None +THING1 = "I am thing1" diff --git a/pylint/test/input/func_w0401_package/thing2.py b/pylint/test/input/func_w0401_package/thing2.py new file mode 100644 index 0000000..987965e --- /dev/null +++ b/pylint/test/input/func_w0401_package/thing2.py @@ -0,0 +1,7 @@ +"""The second thing.""" +# pylint: disable=no-absolute-import +__revision__ = None +from .all_the_things import THING1 + +THING2 = "I am thing2" +THING1_PLUS_THING2 = "%s, plus %s" % (THING1, THING2) diff --git a/pylint/test/input/func_w0402.py b/pylint/test/input/func_w0402.py new file mode 100644 index 0000000..9f7136e --- /dev/null +++ b/pylint/test/input/func_w0402.py @@ -0,0 +1,12 @@ +"""test wildard import +""" +__revision__ = 0 +# pylint: disable=no-absolute-import +from input.func_fixme import * +# This is an unresolved import which still generates the wildcard-import +# warning. +from unknown.package import * + +def abcd(): + """use imports""" + function() diff --git a/pylint/test/input/func_w0404.py b/pylint/test/input/func_w0404.py new file mode 100644 index 0000000..d65da51 --- /dev/null +++ b/pylint/test/input/func_w0404.py @@ -0,0 +1,27 @@ +"""Unittests for W0404 (reimport)""" +from __future__ import absolute_import, print_function +__revision__ = 0 + +import sys + +import xml.etree.ElementTree +from xml.etree import ElementTree + +from email import encoders +import email.encoders + +import sys + +def no_reimport(): + """docstring""" + import os + print(os) + + +def reimport(): + """This function contains a reimport.""" + import sys + del sys + + +del sys, ElementTree, xml.etree.ElementTree, encoders, email.encoders diff --git a/pylint/test/input/func_w0405.py b/pylint/test/input/func_w0405.py new file mode 100644 index 0000000..8071ab2 --- /dev/null +++ b/pylint/test/input/func_w0405.py @@ -0,0 +1,31 @@ +"""check reimport +""" +from __future__ import absolute_import, print_function +__revision__ = 0 + +import os +from os.path import join, exists + +import os +import re as _re + +_re.match('yo', '.*') + +if __revision__: + print(os) + from os.path import exists + print(join, exists) + +def func(yooo): + """reimport in different scope""" + import os as ass + ass.remove(yooo) + import re + re.compile('.*') + +if 1: + import sys + print(sys.modules) +else: + print('bla') + import sys diff --git a/pylint/test/input/func_w0406.py b/pylint/test/input/func_w0406.py new file mode 100644 index 0000000..84a5550 --- /dev/null +++ b/pylint/test/input/func_w0406.py @@ -0,0 +1,9 @@ +"""test module importing itself""" +# pylint: disable=no-absolute-import +from __future__ import print_function +__revision__ = 0 + +import func_w0406 + +if __revision__: + print(func_w0406) diff --git a/pylint/test/input/func_w0611.py b/pylint/test/input/func_w0611.py new file mode 100644 index 0000000..44b24d9 --- /dev/null +++ b/pylint/test/input/func_w0611.py @@ -0,0 +1,25 @@ +"""check unused import +""" +# pylint: disable=print-statement, no-absolute-import + +__revision__ = 1 + +import os +import sys + +class NonRegr(object): + """???""" + def __init__(self): + print 'initialized' + + def sys(self): + """should not get sys from there...""" + print self, sys + + def dummy(self, truc): + """yo""" + return self, truc + + def blop(self): + """yo""" + print self, 'blip' diff --git a/pylint/test/input/func_w0612.py b/pylint/test/input/func_w0612.py new file mode 100644 index 0000000..678185b --- /dev/null +++ b/pylint/test/input/func_w0612.py @@ -0,0 +1,37 @@ +"""test unused variable +""" +# pylint: disable=invalid-name, redefined-outer-name, print-statement, no-absolute-import +__revision__ = 0 +PATH = OS = collections = deque = None + +def function(matches): + """"yo""" + aaaa = 1 + index = -1 + for match in matches: + index += 1 + print match + +def visit_if(self, node): + """increments the branches counter""" + branches = 1 + # don't double count If nodes coming from some 'elif' + if node.orelse and len(node.orelse) > 1: + branches += 1 + self.inc_branch(branches) + self.stmts += branches + +def test_global(): + """ Test various assignments of global + variables through imports. + """ + global PATH, OS, collections, deque + from os import path as PATH + import os as OS + import collections + from collections import deque + # make sure that these triggers unused-variable + from sys import platform + from sys import version as VERSION + import this + import re as RE diff --git a/pylint/test/input/func_w0613.py b/pylint/test/input/func_w0613.py new file mode 100644 index 0000000..333699c --- /dev/null +++ b/pylint/test/input/func_w0613.py @@ -0,0 +1,42 @@ +# pylint: disable=R0903, print-statement +"""test unused argument +""" + +__revision__ = 1 + +def function(arg=1): + """ignore arg""" + + +class AAAA(object): + """dummy class""" + + def method(self, arg): + """dummy method""" + print self + def __init__(self, *unused_args, **unused_kwargs): + pass + + @classmethod + def selected(cls, *args, **kwargs): + """called by the registry when the vobject has been selected. + """ + return cls + + def using_inner_function(self, etype, size=1): + """return a fake result set for a particular entity type""" + rset = AAAA([('A',)]*size, '%s X' % etype, + description=[(etype,)]*size) + def inner(row, col=0, etype=etype, req=self, rset=rset): + """inner using all its argument""" + # pylint: disable = E1103 + return req.vreg.etype_class(etype)(req, rset, row, col) + # pylint: disable = W0201 + rset.get_entity = inner + +class BBBB(object): + """dummy class""" + + def __init__(self, arg): + """Constructor with an extra parameter. Should raise a warning""" + self.spam = 1 diff --git a/pylint/test/input/func_w0623_py30.py b/pylint/test/input/func_w0623_py30.py new file mode 100644 index 0000000..f6c5f57 --- /dev/null +++ b/pylint/test/input/func_w0623_py30.py @@ -0,0 +1,16 @@ +"""Test for W0623, overwriting names in exception handlers.""" + +__revision__ = '' + +class MyError(Exception): + """Special exception class.""" + pass + + +def some_function(): + """A function.""" + + try: + {}["a"] + except KeyError, some_function: # W0623 + pass diff --git a/pylint/test/input/func_w0623_py_30.py b/pylint/test/input/func_w0623_py_30.py new file mode 100644 index 0000000..e5c2231 --- /dev/null +++ b/pylint/test/input/func_w0623_py_30.py @@ -0,0 +1,67 @@ +"""Test for W0623, overwriting names in exception handlers.""" +# pylint: disable=broad-except,bare-except,pointless-except,print-statement,no-absolute-import +__revision__ = '' + +import exceptions + +class MyError(Exception): + """Special exception class.""" + pass + + +def some_function(): + """A function.""" + exc = None + + try: + {}["a"] + except KeyError, exceptions.RuntimeError: # W0623 + pass + except KeyError, OSError: # W0623 + pass + except KeyError, MyError: # W0623 + pass + except KeyError, exc: # this is fine + print exc + except KeyError, exc1: # this is fine + print exc1 + except KeyError, FOO: # C0103 + print FOO + + try: + pass + except KeyError, exc1: # this is fine + print exc1 + +class MyOtherError(Exception): + """Special exception class.""" + pass + + +exc3 = None + +try: + pass +except KeyError, exceptions.RuntimeError: # W0623 + pass +except KeyError, exceptions.RuntimeError.args: # W0623 + pass +except KeyError, OSError: # W0623 + pass +except KeyError, MyOtherError: # W0623 + pass +except KeyError, exc3: # this is fine + print exc3 +except KeyError, exc4: # this is fine + print exc4 +except KeyError, OOPS: # C0103 + print OOPS + +try: + pass +except KeyError, exc4: # this is fine + print exc4 +except IOError, exc5: # this is fine + print exc5 +except MyOtherError, exc5: # this is fine + print exc5 diff --git a/pylint/test/input/func_w0631.py b/pylint/test/input/func_w0631.py new file mode 100644 index 0000000..0390ac7 --- /dev/null +++ b/pylint/test/input/func_w0631.py @@ -0,0 +1,20 @@ +"""Check possible undefined loopvar +""" +from __future__ import print_function +__revision__ = 0 + +def do_stuff(some_random_list): + """This is not right.""" + for var in some_random_list: + pass + print(var) + + +def do_else(some_random_list): + """This is not right.""" + for var in some_random_list: + if var == 42: + break + else: + var = 84 + print(var) diff --git a/pylint/test/input/func_w0702.py b/pylint/test/input/func_w0702.py new file mode 100644 index 0000000..1f82a23 --- /dev/null +++ b/pylint/test/input/func_w0702.py @@ -0,0 +1,17 @@ +"""check empty except statement +""" +from __future__ import print_function +__revision__ = 0 + +if __revision__: + try: + print(__revision__) + except: + print('error') + +try: + __revision__ += 1 +except TypeError: + print('error') +except Exception: + print('error') diff --git a/pylint/test/input/func_w0703.py b/pylint/test/input/func_w0703.py new file mode 100644 index 0000000..fb633fd --- /dev/null +++ b/pylint/test/input/func_w0703.py @@ -0,0 +1,9 @@ +"""check empty except statement +""" +from __future__ import print_function +__revision__ = 0 + +try: + __revision__ += 1 +except Exception: + print('error') diff --git a/pylint/test/input/func_w0704.py b/pylint/test/input/func_w0704.py new file mode 100644 index 0000000..524df17 --- /dev/null +++ b/pylint/test/input/func_w0704.py @@ -0,0 +1,16 @@ +"""test empty except +""" + +__revision__ = 1 + +try: + __revision__ += 1 +except TypeError: + pass + +try: + __revision__ += 1 +except TypeError: + pass +else: + __revision__ = None diff --git a/pylint/test/input/func_w0705.py b/pylint/test/input/func_w0705.py new file mode 100644 index 0000000..0a77ac2 --- /dev/null +++ b/pylint/test/input/func_w0705.py @@ -0,0 +1,46 @@ +"""test misordered except +""" + +__revision__ = 1 + +try: + __revision__ += 1 +except Exception: + __revision__ = None +except TypeError: + __revision__ = None + +try: + __revision__ += 1 +except LookupError: + __revision__ = None +except IndexError: + __revision__ = None + +try: + __revision__ += 1 +except (LookupError, NameError): + __revision__ = None +except (IndexError, UnboundLocalError): + __revision__ = None + +try: + __revision__ += 1 +except: + pass +except Exception: + pass + +try: + __revision__ += 1 +except TypeError: + __revision__ = None +except: + __revision__ = None + +try: + __revision__ += 1 +except Exception: + pass +except: + pass diff --git a/pylint/test/input/func_w0801.py b/pylint/test/input/func_w0801.py new file mode 100644 index 0000000..cd386ff --- /dev/null +++ b/pylint/test/input/func_w0801.py @@ -0,0 +1,11 @@ +"""test code similarities +by defaut docstring are not considered +""" +__revision__ = 'id' +A = 2 +B = 3 +C = A + B +# need more than X lines to trigger the message +C *= 2 +A -= B +# all this should be detected diff --git a/pylint/test/input/func_w1201.py b/pylint/test/input/func_w1201.py new file mode 100644 index 0000000..a9791d9 --- /dev/null +++ b/pylint/test/input/func_w1201.py @@ -0,0 +1,21 @@ +# pylint: disable=E1101, no-absolute-import +"""test checking use of the logging module +""" + +__revision__ = '' + +# Muck up the names in an effort to confuse... +import logging as renamed_logging +import os as logging + +# Statements that should be flagged: +renamed_logging.warn('%s, %s' % (4, 5)) +renamed_logging.exception('%s' % 'Exceptional!') +renamed_logging.log(renamed_logging.INFO, 'msg: %s' % 'Run!') + +# Statements that should not be flagged: +renamed_logging.warn('%s, %s', 4, 5) +renamed_logging.log(renamed_logging.INFO, 'msg: %s', 'Run!') +renamed_logging.warn('%s' + ' the rest of a single string') +logging.warn('%s, %s' % (4, 5)) +logging.log(logging.INFO, 'msg: %s' % 'Run!') diff --git a/pylint/test/input/func_w1202.py b/pylint/test/input/func_w1202.py new file mode 100644 index 0000000..efe6b1a --- /dev/null +++ b/pylint/test/input/func_w1202.py @@ -0,0 +1,26 @@ +# pylint: disable=E1101, no-absolute-import +"""test checking use of the logging module +""" + +__revision__ = '' + +import __builtin__ + +# Muck up the names in an effort to confuse... +import logging as renamed_logging +import os as logging + +FORMAT_STR = '{0}, {1}' + +# Statements that should be flagged: +renamed_logging.debug('{0}, {1}'.format(4, 5)) +renamed_logging.log(renamed_logging.DEBUG, 'msg: {}'.format('Run!')) +renamed_logging.debug(FORMAT_STR.format(4, 5)) +renamed_logging.log(renamed_logging.DEBUG, FORMAT_STR.format(4, 5)) + +# Statements that should not be flagged: +renamed_logging.debug(format(66, 'x')) +renamed_logging.debug(__builtin__.format(66, 'x')) +renamed_logging.log(renamed_logging.DEBUG, 'msg: Run!'.upper()) +logging.debug('{0}, {1}'.format(4, 5)) +logging.log(logging.DEBUG, 'msg: {}'.format('Run!')) diff --git a/pylint/test/input/func_with_without_as_py25.py b/pylint/test/input/func_with_without_as_py25.py new file mode 100644 index 0000000..7ecf574 --- /dev/null +++ b/pylint/test/input/func_with_without_as_py25.py @@ -0,0 +1,12 @@ +'''This is a little non regression test on a with statement +without 'as'. +''' +from __future__ import with_statement, print_function +__revision__ = 32321313 + +def do_nothing(arg): + 'ho foo' + print(arg) + with open('x'): + base.baz + base = 7 diff --git a/pylint/test/input/ignore_except_pass_by_default.py b/pylint/test/input/ignore_except_pass_by_default.py new file mode 100644 index 0000000..444e540 --- /dev/null +++ b/pylint/test/input/ignore_except_pass_by_default.py @@ -0,0 +1,6 @@ +"""#5575: by default no W0704 warning on bare pass in except""" + +try: + __exception__ = 0 +except ValueError: + pass diff --git a/pylint/test/input/indirect1.py b/pylint/test/input/indirect1.py new file mode 100644 index 0000000..eac6242 --- /dev/null +++ b/pylint/test/input/indirect1.py @@ -0,0 +1,4 @@ +class TotoInterface: + def machin(self): + raise NotImplementedError + diff --git a/pylint/test/input/indirect2.py b/pylint/test/input/indirect2.py new file mode 100644 index 0000000..6eefece --- /dev/null +++ b/pylint/test/input/indirect2.py @@ -0,0 +1,7 @@ +from indirect1 import TotoInterface + +class AbstractToto: + __implements__ = TotoInterface + + def helper(self): + return 'help' diff --git a/pylint/test/input/indirect3.py b/pylint/test/input/indirect3.py new file mode 100644 index 0000000..dac0853 --- /dev/null +++ b/pylint/test/input/indirect3.py @@ -0,0 +1,5 @@ +from indirect2 import AbstractToto + +class ConcreteToto(AbstractToto): + def machin(self): + return self.helper()*2 diff --git a/pylint/test/input/noext b/pylint/test/input/noext new file mode 100644 index 0000000..8aeda06 --- /dev/null +++ b/pylint/test/input/noext @@ -0,0 +1,4 @@ +#!/usr/bin/env python +"""a python file without .py extension""" + +__revision__ = None diff --git a/pylint/test/input/similar1 b/pylint/test/input/similar1 new file mode 100644 index 0000000..2b04ee2 --- /dev/null +++ b/pylint/test/input/similar1 @@ -0,0 +1,22 @@ +import one +from two import two +three +four +five +six # comments optionally ignored +seven +eight +nine +''' ten +eleven +twelve ''' +thirteen +fourteen +fifteen + + + + +sixteen +seventeen +eighteen diff --git a/pylint/test/input/similar2 b/pylint/test/input/similar2 new file mode 100644 index 0000000..77f5f1e --- /dev/null +++ b/pylint/test/input/similar2 @@ -0,0 +1,22 @@ +import one +from two import two +three +four +five +six +seven +eight +nine +''' ten +ELEVEN +twelve ''' +thirteen +fourteen +FIFTEEN + + + + +sixteen +seventeen +eighteen diff --git a/pylint/test/input/syntax_error.py b/pylint/test/input/syntax_error.py new file mode 100644 index 0000000..6c1e7a7 --- /dev/null +++ b/pylint/test/input/syntax_error.py @@ -0,0 +1,2 @@ +if False: +print('hop') diff --git a/pylint/test/input/w0401_cycle.py b/pylint/test/input/w0401_cycle.py new file mode 100644 index 0000000..cea6b93 --- /dev/null +++ b/pylint/test/input/w0401_cycle.py @@ -0,0 +1,9 @@ +"""w0401 dependency +""" +# pylint: disable=print-statement, no-absolute-import +__revision__ = 0 + +import input.func_w0401 + +if __revision__: + print input diff --git a/pylint/test/input/w0801_same.py b/pylint/test/input/w0801_same.py new file mode 100644 index 0000000..cd386ff --- /dev/null +++ b/pylint/test/input/w0801_same.py @@ -0,0 +1,11 @@ +"""test code similarities +by defaut docstring are not considered +""" +__revision__ = 'id' +A = 2 +B = 3 +C = A + B +# need more than X lines to trigger the message +C *= 2 +A -= B +# all this should be detected |