Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • pycqa/pep8-naming
1 result
Show changes
Commits on Source (5)
Loading
Loading
@@ -19,6 +19,11 @@ UPPERCASE_REGEX = re.compile(r'[_A-Z][_A-Z0-9]*$')
MIXEDCASE_REGEX = re.compile(r'_?[A-Z][a-zA-Z0-9]*$')
 
 
# Node types which may contain class methods
METHOD_CONTAINER_NODES = {ast.If, ast.While, ast.For, ast.With} | (
{ast.TryExcept, ast.TryFinally} if sys.version_info[0] == 2 else {ast.Try})
if sys.version_info[0] < 3:
def _unpack_args(args):
ret = []
Loading
Loading
@@ -184,9 +189,15 @@ class NamingChecker(object):
# If this class inherits from `type`, it's a metaclass, and we'll
# consider all of it's methods to be classmethods.
ismetaclass = any(name for name in cls_bases if name.id == 'type')
self.set_function_nodes_types(
iter_child_nodes(cls_node), ismetaclass, late_decoration)
 
def set_function_nodes_types(self, nodes, ismetaclass, late_decoration):
# iterate over all functions and tag them
for node in iter_child_nodes(cls_node):
for node in nodes:
if type(node) in METHOD_CONTAINER_NODES:
self.set_function_nodes_types(
iter_child_nodes(node), ismetaclass, late_decoration)
if not isinstance(node, ast.FunctionDef):
continue
node.function_type = _FunctionType.METHOD
Loading
Loading
@@ -225,6 +236,8 @@ class ClassNameCheck(BaseASTCheck):
N801 = "class name '{name}' should use CapWords convention"
 
def visit_classdef(self, node, parents, ignore=None):
if ignore and node.name in ignore:
return
if not self.check(node.name):
yield self.err(node, 'N801', node.name)
 
Loading
Loading
#: Okay
class C1:
def __str__(self):
return ''
#: Okay
class C2:
if True:
def __str__(self):
return ''
#: N807
if True:
def __bad__():
pass
#: Okay
class C3:
try:
if True:
while True:
def __str__(self):
return ''
break
except:
pass
#: N807
def __bad():
pass
Loading
Loading