Use 'object' for resolving only specific attributes of 'module' (PY-7823)

This commit is contained in:
Andrey Vlasovskikh
2013-04-18 21:16:44 +04:00
parent d6972abf2a
commit e2f2bc616f
4 changed files with 14 additions and 5 deletions
@@ -298,10 +298,12 @@ public class PyReferenceImpl implements PsiReferenceEx, PsiPolyVariantReference
PyBuiltinCache builtins_cache = PyBuiltinCache.getInstance(realContext);
if (uexpr == null) {
// ...as a part of current module
PyType otype = builtins_cache.getObjectType(); // "object" as a closest kin to "module"
String name = myElement.getName();
if (otype != null && name != null) {
ret.addAll(otype.resolveMember(name, null, AccessDirection.READ, myContext));
if (PyModuleType.MODULE_MEMBERS.contains(name)) {
PyType otype = builtins_cache.getObjectType(); // "object" as a closest kin to "module"
if (otype != null && name != null) {
ret.addAll(otype.resolveMember(name, null, AccessDirection.READ, myContext));
}
}
}
if (uexpr == null) {
@@ -40,7 +40,8 @@ public class PyModuleType implements PyType { // Modules don't descend from obje
@NotNull private final PyFile myModule;
@Nullable private final PyImportedModule myImportedModule;
protected static ImmutableSet<String> ourPossibleFields = ImmutableSet.of("__name__", "__file__", "__path__", "__doc__", "__dict__", "__package__");
public static final ImmutableSet<String> MODULE_MEMBERS = ImmutableSet.of(
"__name__", "__file__", "__path__", "__doc__", "__dict__", "__package__");
public PyModuleType(@NotNull PyFile source) {
this(source, null);
@@ -358,7 +359,7 @@ public class PyModuleType implements PyType { // Modules don't descend from obje
@NotNull
public static Set<String> getPossibleInstanceMembers() {
return ourPossibleFields;
return MODULE_MEMBERS;
}
}
@@ -0,0 +1 @@
<error descr="Unresolved reference '__init__'">__init__</error>
@@ -262,6 +262,11 @@ public class PyUnresolvedReferencesInspectionTest extends PyTestCase {
doTest();
}
// PY-7823
public void testUnresolvedTopLevelInit() {
doTest();
}
private void doTest() {
myFixture.configureByFile(TEST_DIRECTORY + getTestName(true) + ".py");
myFixture.enableInspections(PyUnresolvedReferencesInspection.class);