Skip to content
This repository has been archived by the owner on Mar 7, 2021. It is now read-only.

Re-apply 0c808db to not raise duplicate function warning for property decorators @prop.setter/deleter. #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 17 additions & 8 deletions pyflakes/checker.py
Expand Up @@ -98,7 +98,7 @@ class Assignment(Binding):




class FunctionDefinition(Binding): class FunctionDefinition(Binding):
pass _property_decorator = False






Expand Down Expand Up @@ -353,8 +353,9 @@ def addBinding(self, loc, value, reportRedef=True):
''' '''
if (isinstance(self.scope.get(value.name), FunctionDefinition) if (isinstance(self.scope.get(value.name), FunctionDefinition)
and isinstance(value, FunctionDefinition)): and isinstance(value, FunctionDefinition)):
self.report(messages.RedefinedFunction, if not value._property_decorator:
loc, value.name, self.scope[value.name].source) self.report(messages.RedefinedFunction,
loc, value.name, self.scope[value.name].source)


if not isinstance(self.scope, ClassScope): if not isinstance(self.scope, ClassScope):
for scope in self.scopeStack[::-1]: for scope in self.scopeStack[::-1]:
Expand Down Expand Up @@ -512,12 +513,20 @@ def NAME(self, node):
def FUNCTIONDEF(self, node): def FUNCTIONDEF(self, node):
# the decorators attribute is called decorator_list as of Python 2.6 # the decorators attribute is called decorator_list as of Python 2.6
if hasattr(node, 'decorators'): if hasattr(node, 'decorators'):
for deco in node.decorators: decorators = node.decorators
self.handleNode(deco, node)
else: else:
for deco in node.decorator_list: decorators = node.decorator_list
self.handleNode(deco, node)
self.addBinding(node, FunctionDefinition(node.name, node)) for deco in decorators:
self.handleNode(deco, node)

# Check for property decorator
func_def = FunctionDefinition(node.name, node)
for decorator in decorators:
if getattr(decorator, 'attr', None) in ('setter', 'deleter'):
func_def._property_decorator = True

self.addBinding(node, func_def)
self.LAMBDA(node) self.LAMBDA(node)


def LAMBDA(self, node): def LAMBDA(self, node):
Expand Down