Skip to content
Snippets Groups Projects
Unverified Commit 42e5bdb9 authored by Ian Stapleton Cordasco's avatar Ian Stapleton Cordasco Committed by GitHub
Browse files

Merge pull request #48 from jparise/function-dunder

Move "__ in function name" check to new N807 code
parents de583598 b656f4a1
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -46,6 +46,8 @@ These error codes are emitted:
+------+-------------------------------------------------------+
| N806 | variable in function should be lowercase |
+------+-------------------------------------------------------+
| N807 | function name should not start or end with '__' |
+------+-------------------------------------------------------+
+------+-------------------------------------------------------+
| N811 | constant imported as non constant |
+------+-------------------------------------------------------+
Loading
Loading
Loading
Loading
@@ -232,22 +232,25 @@ class FunctionNameCheck(BaseASTCheck):
"""
Function names should be lowercase, with words separated by underscores
as necessary to improve readability.
Functions *not* beeing methods '__' in front and back are not allowed.
Functions *not* being methods '__' in front and back are not allowed.
 
mixedCase is allowed only in contexts where that's already the
prevailing style (e.g. threading.py), to retain backwards compatibility.
"""
check = LOWERCASE_REGEX.match
N802 = "function name '{name}' should be lowercase xxx"
N807 = "function name '{name}' should not start or end with '__'"
 
def visit_functiondef(self, node, parents, ignore=None):
function_type = getattr(node, 'function_type', _FunctionType.FUNCTION)
name = node.name
if ignore and name in ignore:
return
if ((function_type == 'function' and '__' in (name[:2], name[-2:])) or
not self.check(name)):
if not self.check(name):
yield self.err(node, 'N802', name)
if function_type == 'function' and '__' in (name[:2], name[-2:]):
yield self.err(node, 'N807', name)
 
 
class FunctionArgNamesCheck(BaseASTCheck):
Loading
Loading
#: Okay
def ok():
pass
#: N802
def __bad():
pass
#: N802
def bad__():
pass
#: N802
def __bad__():
pass
#: Okay
def _ok():
pass
Loading
Loading
@@ -47,11 +38,6 @@ class ClassName(object):
class ClassName(object):
def notOk(self):
pass
#: N802
class ClassName(object):
def method(self):
def __bad():
pass
#: Okay
def setUp():
pass
Loading
Loading
#: N807
def __bad():
pass
#: N807
def bad__():
pass
#: N807
def __bad__():
pass
#: N807
class ClassName(object):
def method(self):
def __bad():
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment