Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ctor_arguments.py 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. """Test function argument checker on __init__
  2. Based on test/functional/arguments.py
  3. """
  4. # pylint: disable=C0111,R0903,W0231
  5. class Class1Arg(object):
  6. def __init__(self, first_argument):
  7. """one argument function"""
  8. class Class3Arg(object):
  9. def __init__(self, first_argument, second_argument, third_argument):
  10. """three arguments function"""
  11. class ClassDefaultArg(object):
  12. def __init__(self, one=1, two=2):
  13. """function with default value"""
  14. class Subclass1Arg(Class1Arg):
  15. pass
  16. class ClassAllArgs(Class1Arg):
  17. def __init__(self, *args, **kwargs):
  18. pass
  19. class ClassMultiInheritance(Class1Arg, Class3Arg):
  20. pass
  21. class ClassNew(object):
  22. def __new__(cls, first_argument, kwarg=None):
  23. return first_argument, kwarg
  24. Class1Arg(420)
  25. Class1Arg() # [no-value-for-parameter]
  26. Class1Arg(1337, 347) # [too-many-function-args]
  27. Class3Arg(420, 789) # [no-value-for-parameter]
  28. # +1:[no-value-for-parameter,no-value-for-parameter,no-value-for-parameter]
  29. Class3Arg()
  30. Class3Arg(1337, 347, 456)
  31. Class3Arg('bab', 'bebe', None, 5.6) # [too-many-function-args]
  32. ClassDefaultArg(1, two=5)
  33. ClassDefaultArg(two=5)
  34. Class1Arg(bob=4) # [no-value-for-parameter,unexpected-keyword-arg]
  35. ClassDefaultArg(1, 4, coin="hello") # [unexpected-keyword-arg]
  36. ClassDefaultArg(1, one=5) # [redundant-keyword-arg]
  37. Subclass1Arg(420)
  38. Subclass1Arg() # [no-value-for-parameter]
  39. Subclass1Arg(1337, 347) # [too-many-function-args]
  40. ClassAllArgs()
  41. ClassAllArgs(1, 2, 3, even=4, more=5)
  42. ClassMultiInheritance(1)
  43. ClassMultiInheritance(1, 2, 3) # [too-many-function-args]
  44. ClassNew(1, kwarg=1)
  45. ClassNew(1, 2, 3) # [too-many-function-args]
  46. ClassNew(one=2) # [no-value-for-parameter,unexpected-keyword-arg]
  47. class Metaclass(type):
  48. def __new__(mcs, name, bases, namespace):
  49. return type.__new__(mcs, name, bases, namespace)
  50. def with_metaclass(meta, base=object):
  51. """Create a new type that can be used as a metaclass."""
  52. return meta("NewBase", (base, ), {})
  53. class ClassWithMeta(with_metaclass(Metaclass)):
  54. pass
  55. ClassWithMeta()
  56. class BuiltinExc(Exception):
  57. def __init__(self, val=True):
  58. self.val = val
  59. BuiltinExc(42, 24, badarg=1) # [too-many-function-args,unexpected-keyword-arg]
  60. class Clsmethod(object):
  61. def __init__(self, first, second):
  62. self.first = first
  63. self.second = second
  64. @classmethod
  65. def from_nothing(cls):
  66. return cls(1, 2, 3, 4) # [too-many-function-args]
  67. @classmethod
  68. def from_nothing1(cls):
  69. return cls() # [no-value-for-parameter,no-value-for-parameter]
  70. @classmethod
  71. def from_nothing2(cls):
  72. # +1: [no-value-for-parameter,unexpected-keyword-arg]
  73. return cls(1, not_argument=2)