public void testRestDocstringIvarNameResolvesToDataClassAttribute() {
runWithDocStringFormat(DocStringFormat.REST, () -> assertResolvesTo(PyTargetExpression.class, "var1"));
}
+
+ // PY-50788
+ public void testRestDocstringIvarNameResolvesToInheritedInstanceAttribute() {
+ runWithDocStringFormat(DocStringFormat.REST, () -> assertResolvesTo(PyTargetExpression.class, "attr"));
+ }
+
+ // PY-50788
+ public void testRestDocstringVarNameResolvesToInheritedInstanceAttribute() {
+ runWithDocStringFormat(DocStringFormat.REST, () -> assertResolvesTo(PyTargetExpression.class, "attr"));
+ }
+
+ // PY-50788
+ public void testRestDocstringVarNameResolvesToInheritedClassAttribute() {
+ runWithDocStringFormat(DocStringFormat.REST, () -> assertResolvesTo(PyTargetExpression.class, "attr"));
+ }
+
+ // PY-50788
+ public void testRestDocstringCvarNameResolvesToInheritedClassAttribute() {
+ runWithDocStringFormat(DocStringFormat.REST, () -> assertResolvesTo(PyTargetExpression.class, "attr"));
+ }
+
+ // PY-50788
+ public void testNumpyDocstringAttributeNameResolvesToInheritedInstanceAttribute() {
+ runWithDocStringFormat(DocStringFormat.NUMPY, () -> assertResolvesTo(PyTargetExpression.class, "bar"));
+ }
+
+ // PY-50788
+ public void testNumpyDocstringAttributeNameResolvesToInheritedClassAttribute() {
+ runWithDocStringFormat(DocStringFormat.NUMPY, () -> assertResolvesTo(PyTargetExpression.class, "bar"));
+ }
}
if (owner instanceof PyFunction) {
return resolveParameter((PyFunction)owner);
}
- if (owner instanceof PyClass) {
- PyClass pyClass = (PyClass)owner;
+ if (owner instanceof PyClass pyClass) {
final PyFunction init = pyClass.findMethodByName(PyNames.INIT, false, null);
if (myType == ReferenceType.PARAMETER) {
return init != null ? resolveParameter(init) : resolveClassVariable(pyClass);
return parameter;
}
}
- PyElement instanceAttr = resolveInstanceVariable(pyClass);
+ final PyElement instanceAttr = resolveInstanceVariable(pyClass);
return instanceAttr != null ? instanceAttr : resolveClassVariable(pyClass);
}
if (myType == ReferenceType.CLASS_VARIABLE) {
}
@Nullable
- private PyTargetExpression resolveInstanceVariable(final PyClass owner) {
- final List<PyTargetExpression> attributes = owner.getInstanceAttributes();
- for (PyTargetExpression element : attributes) {
- if (getCanonicalText().equals(element.getName())) {
- return element;
- }
- }
- return null;
+ private PyTargetExpression resolveInstanceVariable(@NotNull PyClass owner) {
+ return owner.findInstanceAttribute(getCanonicalText(), true);
}
@Nullable
- private PyTargetExpression resolveClassVariable(@NotNull final PyClass owner) {
- final List<PyTargetExpression> attributes = owner.getClassAttributes();
- for (PyTargetExpression element : attributes) {
- if (getCanonicalText().equals(element.getName())) {
- return element;
- }
- }
- return null;
+ private PyTargetExpression resolveClassVariable(@NotNull PyClass owner) {
+ return owner.findClassAttribute(getCanonicalText(), true, null);
}
@Nullable
--- /dev/null
+class Foo:
+ """
+ Attributes
+ ----------
+ bar
+ Something cool
+ """
+
+ bar = 1
+
+
+class Baz(Foo):
+ """
+ Attributes
+ ----------
+ bar
+ <ref>
+ Re-documented but does exist still.
+ """
\ No newline at end of file
--- /dev/null
+class Foo:
+ """
+ Attributes
+ ----------
+ bar
+ Something cool
+ """
+
+ def __init__(self):
+ self.bar = 1
+
+
+class Baz(Foo):
+ """
+ Attributes
+ ----------
+ bar
+ <ref>
+ Re-documented but does exist still.
+ """
\ No newline at end of file
--- /dev/null
+class Parent:
+ """
+ :cvar attr: parent attr doc
+ """
+ attr = 0
+
+
+class Child(Parent):
+ """
+ :cvar attr: child attr doc
+ <ref>
+ """
--- /dev/null
+class Parent:
+ """
+ :ivar attr: parent attr doc
+ """
+ def __init__(self):
+ self.attr = 0
+
+
+class Child(Parent):
+ """
+ :ivar attr: child attr doc
+ <ref>
+ """
\ No newline at end of file
--- /dev/null
+class Parent:
+ """
+ :var attr: parent attr doc
+ """
+ attr = 0
+
+
+class Child(Parent):
+ """
+ :var attr: child attr doc
+ <ref>
+ """
--- /dev/null
+class Parent:
+ """
+ :var attr: parent attr doc
+ """
+ def __init__(self):
+ self.attr = 0
+
+
+class Child(Parent):
+ """
+ :var attr: child attr doc
+ <ref>
+ """
\ No newline at end of file