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.

name_styles.py 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. """Test for the invalid-name warning."""
  2. # pylint: disable=no-absolute-import
  3. from __future__ import print_function
  4. import abc
  5. import collections
  6. GOOD_CONST_NAME = ''
  7. bad_const_name = 0 # [invalid-name]
  8. def BADFUNCTION_name(): # [invalid-name]
  9. """Bad function name."""
  10. BAD_LOCAL_VAR = 1 # [invalid-name]
  11. print(BAD_LOCAL_VAR)
  12. def func_bad_argname(NOT_GOOD): # [invalid-name]
  13. """Function with a badly named argument."""
  14. return NOT_GOOD
  15. def no_nested_args(arg1, arg21, arg22):
  16. """Well-formed function."""
  17. print(arg1, arg21, arg22)
  18. class bad_class_name(object): # [invalid-name]
  19. """Class with a bad name."""
  20. class CorrectClassName(object):
  21. """Class with a good name."""
  22. def __init__(self):
  23. self._good_private_name = 10
  24. self.__good_real_private_name = 11
  25. self.good_attribute_name = 12
  26. self._Bad_AtTR_name = None # [invalid-name]
  27. self.Bad_PUBLIC_name = None # [invalid-name]
  28. zz = 'Why Was It Bad Class Attribute?'
  29. GOOD_CLASS_ATTR = 'Good Class Attribute'
  30. def BadMethodName(self): # [invalid-name]
  31. """A Method with a bad name."""
  32. def good_method_name(self):
  33. """A method with a good name."""
  34. def __DunDER_IS_not_free_for_all__(self): # [invalid-name]
  35. """Another badly named method."""
  36. class DerivedFromCorrect(CorrectClassName):
  37. """A derived class with an invalid inherited members.
  38. Derived attributes and methods with invalid names do not trigger warnings.
  39. """
  40. zz = 'Now a good class attribute'
  41. def __init__(self):
  42. super(DerivedFromCorrect, self).__init__()
  43. self._Bad_AtTR_name = None # Ignored
  44. def BadMethodName(self):
  45. """Ignored since the method is in the interface."""
  46. V = [WHAT_Ever_inListComp for WHAT_Ever_inListComp in GOOD_CONST_NAME]
  47. def class_builder():
  48. """Function returning a class object."""
  49. class EmbeddedClass(object):
  50. """Useless class."""
  51. return EmbeddedClass
  52. # +1:[invalid-name]
  53. BAD_NAME_FOR_CLASS = collections.namedtuple('Named', ['tuple'])
  54. NEXT_BAD_NAME_FOR_CLASS = class_builder() # [invalid-name]
  55. GoodName = collections.namedtuple('Named', ['tuple'])
  56. ToplevelClass = class_builder()
  57. # Aliases for classes have the same name constraints.
  58. AlsoCorrect = CorrectClassName
  59. NOT_CORRECT = CorrectClassName # [invalid-name]
  60. def test_globals():
  61. """Names in global statements are also checked."""
  62. global NOT_CORRECT
  63. global AlsoCorrect # [invalid-name]
  64. NOT_CORRECT = 1
  65. AlsoCorrect = 2
  66. class FooClass(object):
  67. """A test case for property names.
  68. Since by default, the regex for attributes is the same as the one
  69. for method names, we check the warning messages to contain the
  70. string 'attribute'.
  71. """
  72. @property
  73. def PROPERTY_NAME(self): # [invalid-name]
  74. """Ignored."""
  75. pass
  76. @abc.abstractproperty
  77. def ABSTRACT_PROPERTY_NAME(self): # [invalid-name]
  78. """Ignored."""
  79. pass
  80. @PROPERTY_NAME.setter
  81. def PROPERTY_NAME_SETTER(self): # [invalid-name]
  82. """Ignored."""
  83. pass
  84. def _nice_and_long_descriptive_private_method_name(self):
  85. """private method with long name"""
  86. pass
  87. def good_public_function_name(good_arg_name):
  88. """This is a perfect public function"""
  89. good_variable_name = 1
  90. return good_variable_name + good_arg_name
  91. def too_long_function_name_in_public_scope(): # [invalid-name]
  92. """Public scope function with a too long name"""
  93. return 12
  94. def _private_scope_function_with_long_descriptive_name():
  95. """Private scope function are cool with long descriptive names"""
  96. return 12
  97. LONG_CONSTANT_NAME_IN_PUBLIC_SCOPE_ARE_OKAY = True
  98. class _AnExceptionalExceptionThatOccursVeryVeryRarely(Exception):
  99. """A very exceptional exception with a nice descriptive name"""
  100. pass