third_party.pylibs.pylint.src/pylint/test/input/func_method_could_be_function.py

61 lines
1.3 KiB
Python
Raw Normal View History

# pylint: disable=R0903,R0922,W0232,print-statement
2006-04-26 10:48:09 +00:00
"""test detection of method which could be a function"""
__revision__ = None
class Toto(object):
"""bla bal abl"""
def __init__(self):
self.aaa = 2
2013-06-18 12:36:29 +00:00
2006-04-26 10:48:09 +00:00
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):
2006-04-26 10:48:09 +00:00
"""an abstract class"""
2013-06-18 12:36:29 +00:00
2006-04-26 10:48:09 +00:00
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"""
2013-06-18 12:36:29 +00:00
2006-04-26 10:48:09 +00:00
def check(self, arg):
"""a concret method, could not be a function since it need
polymorphism benefits
"""
return arg == 0
class Super(object):
2006-04-26 10:48:09 +00:00
"""same as before without abstract"""
attr = 1
2006-04-26 10:48:09 +00:00
def method(self):
"""regular"""
print self.attr
2006-04-26 10:48:09 +00:00
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