Inspection to warn about decorators nested over @{class,static}method.

This commit is contained in:
Dmitry Cheryasov
2010-09-05 15:36:17 +03:00
parent e1ca0a5b0d
commit 8cee7ea9a9
4 changed files with 85 additions and 1 deletions
@@ -135,6 +135,10 @@ INSP.usually.named.self=Usually first parameter of a method is named 'self'
INSP.usually.named.cls=Usually first parameter of such methods is named 'cls'
INSP.first.param.must.not.be.tuple=First parameter of a non-static method must not be a tuple
# PyNestedDecoratorsInspection
INSP.NAME.nested.decorators=Problematic nesting of decorators
INSP.decorator.receives.unexpected.builtin=This decorator will not receive a callable it may expect; the built-in decorator returns a special object
# PyRedeclarationInspection
INSP.NAME.redeclaration=Names redeclared without usage
INSP.shadows.same.named.$0.above=Shadows same-named {0} above
@@ -43,7 +43,8 @@ public class PythonInspectionToolProvider implements InspectionToolProvider {
PyCallingNonCallableInspection.class,
PyPropertyAccessInspection.class,
PyPropertyDefinitionInspection.class,
PyInconsistentIndentationInspection.class
PyInconsistentIndentationInspection.class,
PyNestedDecoratorsInspection.class,
};
}
}
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>decorated.py</file>
<line>25</line>
<description>This decorator will not receive a callable it may expect; the built-in decorator returns a special object</description>
</problem>
<problem>
<file>decorated.py</file>
<line>30</line>
<description>This decorator will not receive a callable it may expect; the built-in decorator returns a special object</description>
</problem>
<problem>
<file>decorated.py</file>
<line>35</line>
<description>This decorator will not receive a callable it may expect; the built-in decorator returns a special object</description>
</problem>
<problem>
<file>decorated.py</file>
<line>40</line>
<description>This decorator will not receive a callable it may expect; the built-in decorator returns a special object</description>
</problem>
<problem>
<file>decorated.py</file>
<line>47</line>
<description>This decorator will not receive a callable it may expect; the built-in decorator returns a special object</description>
</problem>
</problems>
@@ -0,0 +1,51 @@
def innocent(f):
"A transparent deco"
print("I'm innocent!")
return f
class A(object):
def f1(self): # nothing
pass
@innocent
@innocent
def f2(cls): # nothing
pass
@classmethod
@innocent
def f2(cls): # nothing
pass
@staticmethod
@innocent
def f4(): # nothing
pass
@innocent # warn
@classmethod
def f3(cls):
pass
@innocent # warn
@staticmethod
def f5():
pass
@classmethod # warn
@staticmethod
def f2(cls):
pass
@innocent # warn
@classmethod
@innocent
def f2(cls):
pass
@innocent
@innocent # warn
@classmethod
@innocent
def f2(cls):
pass