correct type for static access to properties (PY-5915)

This commit is contained in:
Dmitry Jemerov
2012-04-03 18:16:43 +02:00
parent ed0e7ca474
commit f001e65d6a
3 changed files with 45 additions and 3 deletions
@@ -216,12 +216,16 @@ public class PyReferenceExpressionImpl extends PyElementImpl implements PyRefere
PyExpression qualifier = getQualifier();
final String name = getName();
if (name != null && qualifier != null) {
PyType qualifier_type = context.getType(qualifier);
if (qualifier_type instanceof PyClassType) {
PyClass pyClass = ((PyClassType)qualifier_type).getPyClass();
PyType qualifierType = context.getType(qualifier);
if (qualifierType instanceof PyClassType) {
final PyClassType classType = (PyClassType)qualifierType;
PyClass pyClass = classType.getPyClass();
if (pyClass != null) {
Property property = pyClass.findProperty(name);
if (property != null) {
if (classType.isDefinition()) {
return Ref.<PyType>create(PyBuiltinCache.getInstance(pyClass).getObjectType(PyNames.PROPERTY));
}
final Maybe<PyFunction> accessor = property.getByDirection(AccessDirection.of(this));
if (!accessor.isDefined()) {
return Ref.create(null);
@@ -0,0 +1,34 @@
# coding=utf-8
"""
Sample of code that use fget
"""
class Parent(object):
"""
parent class to show a simply property
"""
@property
def attribute(self):
"""
some attribute in parent
"""
return True
class Child(Parent):
"""
child class
"""
@property
def attribute(self):
"""
do something before execute code of parent attribute
"""
print "i'm the child"
return Parent.attribute.fget(self)
if __name__ == '__main__':
child = Child()
print child.attribute
@@ -93,6 +93,10 @@ public class PyUnresolvedReferencesInspectionTest extends PyTestCase {
doMultiFileTest();
}
public void testPropertyType() { // PY-5915
doTest();
}
private void doMultiFileTest() {
myFixture.copyFileToProject("inspections/PyUnresolvedReferencesInspection/__init__.py", "PyUnresolvedReferencesInspection/__init__.py");
myFixture.copyFileToProject("inspections/PyUnresolvedReferencesInspection/" + getTestName(true) + ".py",