pep8.py icon indicating copy to clipboard operation
pep8.py copied to clipboard

Class and function names

Open Kaja opened this issue 16 years ago • 1 comments

Hello,

Do you have any interest in adding verification of class and function names? I have added two functions to check them:

diff --git a/pep8.py b/pep8.py index e7e16cf..51dc35c 100755 --- a/pep8.py +++ b/pep8.py @@ -42,6 +42,7 @@ W warnings 500 line length 600 deprecation 700 statements +800 naming conventions

You can add checks to this program by writing plugins. Each plugin is a simple function that is called for each line of source code, either @@ -111,6 +112,8 @@ DEFAULT_EXCLUDE = '.svn,CVS,.bzr,.hg,.git' INDENT_REGEX = re.compile(r'([ \t])') RAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s(,)') SELFTEST_REGEX = re.compile(r'(Okay|W\d\d\d|E\d\d\d):\s(.)') +CLASS_NAME_REGEX = re.compile(r'^(class )(|[A-Z])([A-Za-z0-9])((([^\w]|[\w]))():)') +FUNCTION_NAME_REGEX = re.compile(r'^(def )(|[a-z])(?[a-z0-9])_((([^\w]|[\w])*)():)')

WHITESPACE = ' \t'

@@ -608,6 +611,29 @@ def python_3000_raise_comma(logical_line): return match.start(1), "W602 deprecated form of raising exception"

+def function_names(logical_line):

  • """
  • Almost without exception, class name use the CapWords convention.
  • Classes for internal use have a leading underscore in addition.
  • """
  • if logical_line.startswith('def '):
  •    match = FUNCTION_NAME_REGEX.match(logical_line)
    
  •    if not match:
    
  •        return 0, "W810 function name policy: not using CapWords."
    
    +def class_names(logical_line):
  • '''
  • Function names should be lower case, with words separated by underscores
  • as necessary to improve readability
  • '''
  • if logical_line.startswith('class '):
  •    match = CLASS_NAME_REGEX.match(logical_line)
    
  •    if not match:
    
  •        return 0, "W820 class name policy."
    
    ##############################################################################

    Helper functions

    ##############################################################################

Kaja avatar Nov 04 '09 06:11 Kaja

I'd like this in too!

dmarkey avatar Mar 22 '12 11:03 dmarkey