Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only check ast.Name for their id in metaclass check #55

Merged
merged 1 commit into from
May 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/pep8ext_naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,10 @@ def tag_class_functions(self, cls_node):
if isinstance(meth, ast.Name):
late_decoration[meth.id] = self.decorator_to_type[func_name]

cls_bases = [b for b in cls_node.bases if isinstance(b, ast.Name)]
# 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_node.bases if name.id == 'type')
ismetaclass = any(name for name in cls_bases if name.id == 'type')

# iterate over all functions and tag them
for node in iter_child_nodes(cls_node):
Expand Down
7 changes: 7 additions & 0 deletions testsuite/N804.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ def __new__(self, name, bases, attrs):
class MetaMethod(type):
def test(cls):
pass
#: Okay
class NotMeta(object):
otherclass = Foo
class AttributeParent(NotMeta.otherclass):
pass
class CallParent(type('_tmp', (), {})):
pass