diff --git a/python/helpers/generator3.py b/python/helpers/generator3.py
index e0c550c3e7b6..447a63403df7 100644
--- a/python/helpers/generator3.py
+++ b/python/helpers/generator3.py
@@ -24,7 +24,7 @@ but seemingly no one uses them in C extensions yet anyway.
# * re.search-bound, ~30% time, in likes of builtins and _gtk with complex docstrings.
# None of this can seemingly be easily helped. Maybe there's a simpler and faster parser library?
-VERSION = "1.107" # Must be a number-dot-number string, updated with each change that affects generated skeletons
+VERSION = "1.108" # Must be a number-dot-number string, updated with each change that affects generated skeletons
# Note: DON'T FORGET TO UPDATE!
VERSION_CONTROL_HEADER_FORMAT = '# from %s by generator %s'
@@ -1795,6 +1795,8 @@ class ModuleRedeclarator(object):
for item_name in sortedNoCase(others.keys()):
item = others[item_name]
self.fmtValue(out, item, indent + 1, prefix=item_name + " = ")
+ if p_name == "object":
+ out(indent + 1, "__module__ = ''")
if others:
out(0, "") # empty line after the block
#
diff --git a/python/helpers/required_gen_version b/python/helpers/required_gen_version
index e8cfa76de1a4..6f3efcf4121d 100644
--- a/python/helpers/required_gen_version
+++ b/python/helpers/required_gen_version
@@ -6,7 +6,7 @@
(default) 1.92 # anything not explicitly marked
-(built-in) 1.106 # skeletons of all built-in modules are built together
+(built-in) 1.108 # skeletons of all built-in modules are built together
# Note: modules like itertools, etc are "(built-in)" and are ignored if given separately
_fileio 1.101
diff --git a/python/pluginTestSrc/com/jetbrains/jython/PyToJavaResolveTest.java b/python/pluginTestSrc/com/jetbrains/jython/PyToJavaResolveTest.java
index 8bda9c0b7989..1bb0d1606c80 100644
--- a/python/pluginTestSrc/com/jetbrains/jython/PyToJavaResolveTest.java
+++ b/python/pluginTestSrc/com/jetbrains/jython/PyToJavaResolveTest.java
@@ -37,7 +37,7 @@ public class PyToJavaResolveTest extends ResolveTestCase {
public void testReturnValue() throws Exception {
PsiElement target = resolve();
Assert.assertTrue(target instanceof PsiMethod);
- Assert.assertEquals("java.util.List", ((PsiMethod) target).getContainingClass().getQualifiedName());
+ Assert.assertEquals(CommonClassNames.JAVA_UTIL_LIST, ((PsiMethod) target).getContainingClass().getQualifiedName());
}
public void testPackageType() throws Exception {
diff --git a/python/src/com/jetbrains/python/PyBundle.properties b/python/src/com/jetbrains/python/PyBundle.properties
index 48fbe99d3c95..fd8828138357 100644
--- a/python/src/com/jetbrains/python/PyBundle.properties
+++ b/python/src/com/jetbrains/python/PyBundle.properties
@@ -454,7 +454,7 @@ refactoring.extract.method.error.cannot.perform.refactoring.no.corresponding.loo
refactoring.extract.method.error.cannot.perform.refactoring.when.execution.flow.is.interrupted=Cannot perform refactoring when execution flow is interrupted
refactoring.extract.method.error.cannot.perform.refactoring.when.from.import.inside=Cannot perform refactoring with from import statement inside code block
refactoring.extract.method.error.cannot.perform.refactoring.using.selected.elements=Cannot perform extract method using selected element(s)
-refactoring.extract.method.error.name.clash=Method name clashes with already existing method name
+refactoring.extract.method.error.name.clash=Method name clashes with already existing name
# extract superclass
refactoring.extract.super.target.path.outside.roots=Target directory is outside the project.
Must be within content roots
diff --git a/python/src/com/jetbrains/python/findUsages/PyUsageTypeProvider.java b/python/src/com/jetbrains/python/findUsages/PyUsageTypeProvider.java
index cc8a6f19ac26..873352c8fab7 100644
--- a/python/src/com/jetbrains/python/findUsages/PyUsageTypeProvider.java
+++ b/python/src/com/jetbrains/python/findUsages/PyUsageTypeProvider.java
@@ -12,6 +12,7 @@ import com.jetbrains.python.psi.impl.CallArgumentsMappingImpl;
import com.jetbrains.python.psi.types.PyType;
import com.jetbrains.python.psi.types.PyTypeReference;
import com.jetbrains.python.psi.types.TypeEvalContext;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
@@ -29,7 +30,7 @@ public class PyUsageTypeProvider implements UsageTypeProviderEx {
return getUsageType(element, UsageTarget.EMPTY_ARRAY);
}
- public UsageType getUsageType(PsiElement element, UsageTarget[] targets) {
+ public UsageType getUsageType(PsiElement element, @NotNull UsageTarget[] targets) {
if (element instanceof PyElement) {
if (PsiTreeUtil.getParentOfType(element, PyImportStatementBase.class) != null) {
return IN_IMPORT;
@@ -76,7 +77,7 @@ public class PyUsageTypeProvider implements UsageTypeProviderEx {
if (targets.length == 1 && targets[0] instanceof PsiElementUsageTarget) {
final PsiElement element = ((PsiElementUsageTarget)targets[0]).getElement();
if (element instanceof PyFunction) {
- PyFunction function = (PyFunction) element;
+ PyFunction function = (PyFunction)element;
final PyFunction.Modifier modifier = function.getModifier();
PyCallExpression.PyMarkedCallee callee = new PyCallExpression.PyMarkedCallee(function, modifier, 1, true);
CallArgumentsMappingImpl mapping = new CallArgumentsMappingImpl(call.getArgumentList());
diff --git a/python/src/com/jetbrains/python/psi/impl/PyBuiltinCache.java b/python/src/com/jetbrains/python/psi/impl/PyBuiltinCache.java
index 95d39591799b..af06d7f8ba71 100644
--- a/python/src/com/jetbrains/python/psi/impl/PyBuiltinCache.java
+++ b/python/src/com/jetbrains/python/psi/impl/PyBuiltinCache.java
@@ -44,6 +44,7 @@ import java.util.Map;
public class PyBuiltinCache {
public static final @NonNls String BUILTIN_FILE = "__builtin__.py";
@NonNls public static final String BUILTIN_FILE_3K = "builtins.py";
+ public static final String EXCEPTIONS_FILE = "exceptions.py";
private PyType STRING_TYPE_PY2 = null;
@@ -99,14 +100,19 @@ public class PyBuiltinCache {
}
@Nullable
- public static PyFile getBuiltinsForSdk(Project project, Sdk sdk) {
+ public static PyFile getBuiltinsForSdk(@NotNull Project project, @NotNull Sdk sdk) {
+ return getSkeletonFile(project, sdk, PythonSdkType.getBuiltinsFileName(sdk));
+ }
+
+ @Nullable
+ public static PyFile getSkeletonFile(@NotNull Project project, @NotNull Sdk sdk, @NotNull String name) {
SdkTypeId sdkType = sdk.getSdkType();
if (sdkType instanceof PythonSdkType) {
// dig out the builtins file, create an instance based on it
final String[] urls = sdk.getRootProvider().getUrls(PythonSdkType.BUILTIN_ROOT_TYPE);
for (String url : urls) {
if (url.contains(PythonSdkType.SKELETON_DIR_NAME)) {
- final String builtins_url = url + "/" + PythonSdkType.getBuiltinsFileName(sdk);
+ final String builtins_url = url + "/" + name;
File builtins = new File(VfsUtil.urlToPath(builtins_url));
if (builtins.isFile() && builtins.canRead()) {
VirtualFile builtins_vfile = LocalFileSystem.getInstance().findFileByIoFile(builtins);
@@ -123,7 +129,7 @@ public class PyBuiltinCache {
return null;
}
- private static final PyBuiltinCache DUD_INSTANCE = new PyBuiltinCache((PyFile)null);
+ private static final PyBuiltinCache DUD_INSTANCE = new PyBuiltinCache(null, null);
@Nullable
static PyType createLiteralCollectionType(final PySequenceExpression sequence, final String name) {
@@ -136,7 +142,9 @@ public class PyBuiltinCache {
}
- private PyFile myBuiltinsFile;
+ @Nullable private PyFile myBuiltinsFile;
+ @Nullable private PyFile myExceptionsFile;
+
public PyBuiltinCache() {
}
@@ -144,8 +152,9 @@ public class PyBuiltinCache {
public static final Key MARKER_KEY = new Key("python.builtins.skeleton.file");
- public PyBuiltinCache(@Nullable final PyFile builtins) {
+ public PyBuiltinCache(@Nullable final PyFile builtins, @Nullable PyFile exceptions) {
myBuiltinsFile = builtins;
+ myExceptionsFile = exceptions;
if (myBuiltinsFile != null) {
myBuiltinsFile.putUserData(MARKER_KEY, ""); // mark this file as builtins
}
@@ -336,6 +345,7 @@ public class PyBuiltinCache {
if (!(the_file instanceof PyFile)) {
return false;
}
- return myBuiltinsFile == the_file; // files are singletons, no need to compare URIs
+ // files are singletons, no need to compare URIs
+ return the_file == myBuiltinsFile || the_file == myExceptionsFile;
}
}
diff --git a/python/src/com/jetbrains/python/psi/resolve/PythonSdkPathCache.java b/python/src/com/jetbrains/python/psi/resolve/PythonSdkPathCache.java
index 9544cb2a31f3..d4db234406c2 100644
--- a/python/src/com/jetbrains/python/psi/resolve/PythonSdkPathCache.java
+++ b/python/src/com/jetbrains/python/psi/resolve/PythonSdkPathCache.java
@@ -94,7 +94,8 @@ public class PythonSdkPathCache extends PythonPathCache implements Disposable {
while (true) {
PyBuiltinCache pyBuiltinCache = myBuiltins.get();
if (pyBuiltinCache == null || !pyBuiltinCache.isValid()) {
- PyBuiltinCache newCache = new PyBuiltinCache(PyBuiltinCache.getBuiltinsForSdk(myProject, mySdk));
+ PyBuiltinCache newCache = new PyBuiltinCache(PyBuiltinCache.getBuiltinsForSdk(myProject, mySdk),
+ PyBuiltinCache.getSkeletonFile(myProject, mySdk, PyBuiltinCache.EXCEPTIONS_FILE));
if (myBuiltins.compareAndSet(pyBuiltinCache, newCache)) {
return newCache;
}
diff --git a/python/src/com/jetbrains/python/refactoring/extractmethod/PyExtractMethodUtil.java b/python/src/com/jetbrains/python/refactoring/extractmethod/PyExtractMethodUtil.java
index 3930a799cfa5..ca9a2e987751 100644
--- a/python/src/com/jetbrains/python/refactoring/extractmethod/PyExtractMethodUtil.java
+++ b/python/src/com/jetbrains/python/refactoring/extractmethod/PyExtractMethodUtil.java
@@ -553,45 +553,26 @@ public class PyExtractMethodUtil {
public PyExtractMethodValidator(final PsiElement element, final Project project) {
myElement = element;
myProject = project;
-
- ScopeOwner owner = ScopeUtil.getScopeOwner(myElement);
- if (owner instanceof PyFunction) {
- owner = ScopeUtil.getScopeOwner(owner);
- }
- final ScopeOwner parent = owner;
-
- if (parent instanceof PyFile){
- final List functions = ((PyFile)parent).getTopLevelFunctions();
- myFunction = new Function() {
- public Boolean fun(@NotNull final String s) {
- for (PyFunction function : functions) {
- if (s.equals(function.getName())){
+ final ScopeOwner parent = ScopeUtil.getScopeOwner(myElement);
+ myFunction = new Function() {
+ @Override
+ public Boolean fun(String s) {
+ ScopeOwner owner = parent;
+ while (owner != null) {
+ if (owner instanceof PyClass) {
+ if (((PyClass)owner).findMethodByName(s, true) != null) {
return false;
}
}
- return true;
+ final Scope scope = ControlFlowCache.getScope(owner);
+ if (scope.containsDeclaration(s)) {
+ return false;
+ }
+ owner = ScopeUtil.getScopeOwner(owner);
}
- };
- }
- else if (parent instanceof PyClass){
- myFunction = new Function() {
- public Boolean fun(@NotNull final String s) {
- return ((PyClass) parent).findMethodByName(s, true) == null;
- }
- };
- }
- else if (parent instanceof PyFunction) {
- final Scope scope = ControlFlowCache.getScope(parent);
- myFunction = new Function() {
- @Override
- public Boolean fun(String s) {
- return !scope.containsDeclaration(s);
- }
- };
- }
- else {
- myFunction = null;
- }
+ return true;
+ }
+ };
}
public String check(final String name) {
diff --git a/python/testData/completion/mro.py b/python/testData/completion/mro.py
index cee5359fcabe..d661f0befef0 100644
--- a/python/testData/completion/mro.py
+++ b/python/testData/completion/mro.py
@@ -2,4 +2,4 @@ class C(object):
pass
-C.__m
\ No newline at end of file
+C.__mr
\ No newline at end of file
diff --git a/python/testData/inspections/PyUnresolvedReferencesInspection/moduleAttribute.py b/python/testData/inspections/PyUnresolvedReferencesInspection/moduleAttribute.py
new file mode 100644
index 000000000000..8e4dec410776
--- /dev/null
+++ b/python/testData/inspections/PyUnresolvedReferencesInspection/moduleAttribute.py
@@ -0,0 +1,12 @@
+class OldStyle:
+ pass
+
+class NewStyle(object):
+ pass
+
+x = OldStyle()
+y = NewStyle()
+print(OldStyle.__module__)
+print(NewStyle.__module__)
+print(x.__module__)
+print(y.__module__)
diff --git a/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java
index f483114d1c9e..9ad2a1b4f9e3 100644
--- a/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java
+++ b/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java
@@ -121,6 +121,11 @@ public class PyUnresolvedReferencesInspectionTest extends PyTestCase {
doTest();
}
+ // PY-6634
+ public void testModuleAttribute() {
+ doTest();
+ }
+
private void doTest() {
myFixture.configureByFile(TEST_DIRECTORY + getTestName(true) + ".py");
myFixture.enableInspections(PyUnresolvedReferencesInspection.class);
diff --git a/python/testSrc/com/jetbrains/python/refactoring/PyExtractMethodTest.java b/python/testSrc/com/jetbrains/python/refactoring/PyExtractMethodTest.java
index 92f92bc08b22..fd71ca35dfbe 100644
--- a/python/testSrc/com/jetbrains/python/refactoring/PyExtractMethodTest.java
+++ b/python/testSrc/com/jetbrains/python/refactoring/PyExtractMethodTest.java
@@ -91,15 +91,15 @@ public class PyExtractMethodTest extends LightMarkedTestCase {
}
public void testNameCollisionClass() {
- doFail("hello", "Method name clashes with already existing method name");
+ doFail("hello", "Method name clashes with already existing name");
}
public void testNameCollisionFile() {
- doFail("hello", "Method name clashes with already existing method name");
+ doFail("hello", "Method name clashes with already existing name");
}
public void testNameCollisionSuperClass() {
- doFail("hello", "Method name clashes with already existing method name");
+ doFail("hello", "Method name clashes with already existing name");
}
public void testOutNotEmptyStatements() {