diff --git a/python/pluginSrc/com/jetbrains/python/facet/PythonFacetType.java b/python/pluginSrc/com/jetbrains/python/facet/PythonFacetType.java index b1f0f0f7e991..9f761daceec5 100644 --- a/python/pluginSrc/com/jetbrains/python/facet/PythonFacetType.java +++ b/python/pluginSrc/com/jetbrains/python/facet/PythonFacetType.java @@ -57,7 +57,7 @@ public class PythonFacetType extends FacetType { diff --git a/python/pluginSrc/com/jetbrains/python/facet/PythonFrameworkSupportProvider.java b/python/pluginSrc/com/jetbrains/python/facet/PythonFrameworkSupportProvider.java index 98586d34b5df..67b1be902efc 100644 --- a/python/pluginSrc/com/jetbrains/python/facet/PythonFrameworkSupportProvider.java +++ b/python/pluginSrc/com/jetbrains/python/facet/PythonFrameworkSupportProvider.java @@ -22,7 +22,7 @@ public class PythonFrameworkSupportProvider extends FrameworkSupportProvider { @Override public Icon getIcon() { - return PythonIcons.Python.Icons.Python; + return PythonIcons.Python.Python; } @NotNull diff --git a/python/psi-api/python-psi-api.iml b/python/psi-api/python-psi-api.iml index 5e3914f028e3..e64340eea3fa 100644 --- a/python/psi-api/python-psi-api.iml +++ b/python/psi-api/python-psi-api.iml @@ -4,6 +4,7 @@ + diff --git a/python/psi-api/resources/icons/com/jetbrains/python/pythonFile.png b/python/psi-api/resources/icons/com/jetbrains/python/pythonFile.png new file mode 100644 index 000000000000..ccd74ff4320c Binary files /dev/null and b/python/psi-api/resources/icons/com/jetbrains/python/pythonFile.png differ diff --git a/python/psi-api/src/com/jetbrains/python/PythonFileType.java b/python/psi-api/src/com/jetbrains/python/PythonFileType.java index abef86b8d2f8..38ebc690451d 100644 --- a/python/psi-api/src/com/jetbrains/python/PythonFileType.java +++ b/python/psi-api/src/com/jetbrains/python/PythonFileType.java @@ -3,10 +3,10 @@ package com.jetbrains.python; import com.intellij.lang.Language; import com.intellij.openapi.fileTypes.LanguageFileType; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.CharsetToolkit; import com.intellij.openapi.vfs.VirtualFile; +import icons.PythonPsiApiIcons; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,15 +27,12 @@ public class PythonFileType extends LanguageFileType { public static PythonFileType INSTANCE = new PythonFileType(); - private final Icon _icon; - public PythonFileType() { this(new PythonLanguage()); } public PythonFileType(Language language) { super(language); - _icon = IconLoader.getIcon("/com/jetbrains/python/icons/pythonFile.png"); } @NotNull @@ -55,7 +52,7 @@ public class PythonFileType extends LanguageFileType { @NotNull public Icon getIcon() { - return _icon; + return PythonPsiApiIcons.PythonFile; } @Override diff --git a/python/psi-api/src/icons/PythonPsiApiIcons.java b/python/psi-api/src/icons/PythonPsiApiIcons.java new file mode 100644 index 000000000000..caeb62572701 --- /dev/null +++ b/python/psi-api/src/icons/PythonPsiApiIcons.java @@ -0,0 +1,17 @@ +package icons; + +import com.intellij.openapi.util.IconLoader; + +import javax.swing.*; + +/** + * NOTE THIS FILE IS AUTO-GENERATED by the build/scripts/icons.gant + * Don't repeat mistakes of others ;-) + */ +public class PythonPsiApiIcons { + private static Icon load(String path) { + return IconLoader.getIcon(path, PythonPsiApiIcons.class); + } + + public static final Icon PythonFile = load("/icons/com/jetbrains/python/pythonFile.png"); // 16x16 +} diff --git a/python/rest/resources/icons/com/jetbrains/rest/rst.png b/python/rest/resources/icons/com/jetbrains/rest/rst.png new file mode 100644 index 000000000000..2b7fcd7d5f78 Binary files /dev/null and b/python/rest/resources/icons/com/jetbrains/rest/rst.png differ diff --git a/python/rest/src/icons/RestIcons.java b/python/rest/src/icons/RestIcons.java index 810d775edecd..7be4044574bc 100644 --- a/python/rest/src/icons/RestIcons.java +++ b/python/rest/src/icons/RestIcons.java @@ -13,5 +13,5 @@ public class RestIcons { return IconLoader.getIcon(path, RestIcons.class); } - public static final Icon Rst = load("/com/jetbrains/rest/res/rst.png"); // 16x16 + public static final Icon Rst = load("/icons/com/jetbrains/rest/rst.png"); // 16x16 } diff --git a/python/src/com/jetbrains/pyqt/tsFile.png b/python/src/com/jetbrains/pyqt/tsFile.png deleted file mode 100644 index 4f962a2bdae2..000000000000 Binary files a/python/src/com/jetbrains/pyqt/tsFile.png and /dev/null differ diff --git a/python/src/com/jetbrains/pyqt/uiForm.png b/python/src/com/jetbrains/pyqt/uiForm.png deleted file mode 100644 index 048cc19dc1c2..000000000000 Binary files a/python/src/com/jetbrains/pyqt/uiForm.png and /dev/null differ diff --git a/python/src/com/jetbrains/python/PythonModuleTypeBase.java b/python/src/com/jetbrains/python/PythonModuleTypeBase.java index 939673643984..f6eb24910cb9 100644 --- a/python/src/com/jetbrains/python/PythonModuleTypeBase.java +++ b/python/src/com/jetbrains/python/PythonModuleTypeBase.java @@ -26,10 +26,10 @@ public abstract class PythonModuleTypeBase extends Modu } public Icon getBigIcon() { - return PythonIcons.Python.Icons.Python_24; + return PythonIcons.Python.Python_24; } public Icon getNodeIcon(final boolean isOpened) { - return PythonIcons.Python.Icons.PythonClosed; + return PythonIcons.Python.PythonClosed; } } diff --git a/python/src/com/jetbrains/python/actions/ExecuteInConsoleAction.java b/python/src/com/jetbrains/python/actions/ExecuteInConsoleAction.java index 5112b1be49c0..94a045f49ce0 100644 --- a/python/src/com/jetbrains/python/actions/ExecuteInConsoleAction.java +++ b/python/src/com/jetbrains/python/actions/ExecuteInConsoleAction.java @@ -123,17 +123,15 @@ public class ExecuteInConsoleAction extends AnAction { selectConsole(project, editor, consumer); } else { - startConsole(project, editor, consumer, e.getData(LangDataKeys.MODULE)); + startConsole(project, consumer, e.getData(LangDataKeys.MODULE)); } } } private static void startConsole(final Project project, - final Editor editor, final Consumer consumer, Module context) { PydevConsoleRunner runner = RunPythonConsoleAction.runPythonConsole(project, context); - assert runner != null; runner.addConsoleListener(new PydevConsoleRunner.ConsoleListener() { @Override public void handleConsoleInitialized(LanguageConsoleViewImpl consoleView) { diff --git a/python/src/com/jetbrains/python/buildout/BuildoutFacetType.java b/python/src/com/jetbrains/python/buildout/BuildoutFacetType.java index 8447c8956857..721baca8787f 100644 --- a/python/src/com/jetbrains/python/buildout/BuildoutFacetType.java +++ b/python/src/com/jetbrains/python/buildout/BuildoutFacetType.java @@ -50,6 +50,6 @@ public class BuildoutFacetType extends FacetType 0) { String firstArg = args[0].getText(); - if (firstArg.equals(cl.getName()) || firstArg.equals(CANONICAL_SELF+"."+ CLASS)) + final String qualifiedName = cl.getQualifiedName(); + if (firstArg.equals(cl.getName()) || firstArg.equals(CANONICAL_SELF+"."+ CLASS) || + (qualifiedName != null && qualifiedName.endsWith(firstArg))) return true; for (PyClass s : cl.iterateAncestorClasses()) { if (firstArg.equals(s.getName())) diff --git a/python/src/com/jetbrains/python/inspections/quickfix/AugmentedAssignmentQuickFix.java b/python/src/com/jetbrains/python/inspections/quickfix/AugmentedAssignmentQuickFix.java index 919b4d3887f0..88fb994f9d7e 100644 --- a/python/src/com/jetbrains/python/inspections/quickfix/AugmentedAssignmentQuickFix.java +++ b/python/src/com/jetbrains/python/inspections/quickfix/AugmentedAssignmentQuickFix.java @@ -5,14 +5,10 @@ import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiComment; import com.intellij.psi.PsiElement; -import com.intellij.psi.tree.TokenSet; import com.intellij.psi.util.PsiTreeUtil; import com.jetbrains.python.PyBundle; -import com.jetbrains.python.PyTokenTypes; import com.jetbrains.python.psi.*; import com.jetbrains.python.psi.impl.PyAugAssignmentStatementImpl; -import com.jetbrains.python.psi.types.PyType; -import com.jetbrains.python.psi.types.TypeEvalContext; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -59,54 +55,21 @@ public class AugmentedAssignmentQuickFix implements LocalQuickFix { if ((leftExpression instanceof PyReferenceExpression || leftExpression instanceof PySubscriptionExpression)) { if (leftExpression.getText().equals(targetText)) { - if (rightExpression instanceof PyNumericLiteralExpression || rightExpression instanceof PyStringLiteralExpression || - rightExpression instanceof PyCallExpression || rightExpression instanceof PyReferenceExpression - || isPercentage(rightExpression) || isCompound(rightExpression) || isMathOperation(rightExpression, expression.getOperator())) { - - final PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project); - final StringBuilder stringBuilder = new StringBuilder(); - final PsiElement psiOperator = expression.getPsiOperator(); - if (psiOperator == null) return; - stringBuilder.append(targetText).append(" "). - append(psiOperator.getText()).append("= ").append(rightExpression.getText()); - final PyAugAssignmentStatementImpl augAssignment = elementGenerator.createFromText(LanguageLevel.forElement(element), - PyAugAssignmentStatementImpl.class, stringBuilder.toString()); - for (PsiComment comment : comments) - augAssignment.add(comment); - statement.replace(augAssignment); - } + final PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project); + final StringBuilder stringBuilder = new StringBuilder(); + final PsiElement psiOperator = expression.getPsiOperator(); + if (psiOperator == null) return; + stringBuilder.append(targetText).append(" "). + append(psiOperator.getText()).append("= ").append(rightExpression.getText()); + final PyAugAssignmentStatementImpl augAssignment = elementGenerator.createFromText(LanguageLevel.forElement(element), + PyAugAssignmentStatementImpl.class, stringBuilder.toString()); + for (PsiComment comment : comments) + augAssignment.add(comment); + statement.replace(augAssignment); } } } } } - private static boolean isCompound(final PyExpression rightExpression) { - if (rightExpression instanceof PyCallExpression) { - final PyType type = rightExpression.getType(TypeEvalContext.fast()); - if (type != null && type.isBuiltin(TypeEvalContext.fast()) && - ("int".equals(type.getName()) || "str".equals(type.getName()))) return true; - } - return false; - } - - private static boolean isPercentage(final PyExpression rightExpression) { - return (rightExpression instanceof PyBinaryExpression && - ((PyBinaryExpression)rightExpression).getLeftExpression() instanceof PyStringLiteralExpression && - ((PyBinaryExpression)rightExpression).getOperator() == PyTokenTypes.PERC); - } - - private static boolean isMathOperation(final PyExpression rightExpression, final PyElementType mainOperator) { - final TokenSet first = TokenSet.create(PyTokenTypes.EXP, PyTokenTypes.FLOORDIV); - final TokenSet second = TokenSet.create(PyTokenTypes.MULT, PyTokenTypes.DIV, PyTokenTypes.PERC); - final TokenSet third = TokenSet.create(PyTokenTypes.PLUS, PyTokenTypes.MINUS); - if (rightExpression instanceof PyBinaryExpression){ - final PyElementType operator = ((PyBinaryExpression)rightExpression).getOperator(); - if (third.contains(mainOperator)) - return true; - else if (second.contains(mainOperator) && (second.contains(operator) || first.contains(operator))) - return true; - } - return false; - } } diff --git a/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java index 51a444988de4..8d8cc37eb9c3 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java @@ -89,13 +89,13 @@ public class PyFunctionImpl extends PyPresentableElementImpl imp final Property property = getProperty(); if (property != null) { if (property.getGetter().valueOrNull() == this) { - return PythonIcons.Python.Icons.PropertyGetter; + return PythonIcons.Python.PropertyGetter; } if (property.getSetter().valueOrNull() == this) { - return PythonIcons.Python.Icons.PropertySetter; + return PythonIcons.Python.PropertySetter; } if (property.getDeleter().valueOrNull() == this) { - return PythonIcons.Python.Icons.PropertyDeleter; + return PythonIcons.Python.PropertyDeleter; } return PlatformIcons.PROPERTY_ICON; } diff --git a/python/src/com/jetbrains/python/refactoring/introduce/parameter/PyIntroduceParameterHandler.java b/python/src/com/jetbrains/python/refactoring/introduce/parameter/PyIntroduceParameterHandler.java index 0148426ac4d3..e72aca56ec5c 100644 --- a/python/src/com/jetbrains/python/refactoring/introduce/parameter/PyIntroduceParameterHandler.java +++ b/python/src/com/jetbrains/python/refactoring/introduce/parameter/PyIntroduceParameterHandler.java @@ -2,6 +2,7 @@ package com.jetbrains.python.refactoring.introduce.parameter; import com.intellij.codeInsight.CodeInsightUtilBase; import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiNamedElement; import com.intellij.psi.PsiReference; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.refactoring.introduce.inplace.InplaceVariableIntroducer; @@ -61,32 +62,55 @@ public class PyIntroduceParameterHandler extends IntroduceHandler { protected boolean isValidIntroduceContext(PsiElement element) { if (element != null) { - final PyFunction function = PsiTreeUtil.getParentOfType(element, PyFunction.class); - final ScopeOwner scopeOwner = ScopeUtil.getScopeOwner(element); - final boolean[] isValid = {true}; - if (scopeOwner != null) { - new PyRecursiveElementVisitor() { - @Override - public void visitPyReferenceExpression(PyReferenceExpression node) { - super.visitPyReferenceExpression(node); - if (ControlFlowCache.getScope(scopeOwner).containsDeclaration(node.getName())) { - isValid[0] = false; - } - } - }.visitElement(element); - } - final PyStatement nonlocalStatement = - PsiTreeUtil.getParentOfType(element, PyNonlocalStatement.class, PyGlobalStatement.class); - final PyStatementList statementList = - PsiTreeUtil.getParentOfType(element, PyStatementList.class); - PyImportStatement importStatement = PsiTreeUtil.getParentOfType(element, PyImportStatement.class); - return function != null && !isResolvedToParameter(element) && isValid[0] && nonlocalStatement == null && - statementList != null && importStatement == null; + if (!isValidPlace(element)) return false; + + return isNotDeclared(element); } return false; } - private boolean isResolvedToParameter(PsiElement element) { + private static boolean isNotDeclared(PsiElement element) { + final ScopeOwner scopeOwner = ScopeUtil.getScopeOwner(element); + final boolean[] isValid = {true}; + + if (scopeOwner != null) { + final String name = element instanceof PsiNamedElement? ((PsiNamedElement)element).getName() : element.getText(); + if (name != null && ControlFlowCache.getScope(scopeOwner).containsDeclaration(name)) { + return false; + } + new PyRecursiveElementVisitor() { + @Override + public void visitPyReferenceExpression(PyReferenceExpression node) { + super.visitPyReferenceExpression(node); + + final String name = node.getName(); + if (name != null && ControlFlowCache.getScope(scopeOwner).containsDeclaration(name)) { + isValid[0] = false; + } + } + }.visitElement(element); + } + return !isResolvedToParameter(element) && isValid[0]; + } + + private static boolean isValidPlace(PsiElement element) { + final PyFunction function = PsiTreeUtil.getParentOfType(element, PyFunction.class); + final PyForPart forPart = PsiTreeUtil.getParentOfType(element, PyForPart.class); + if (forPart != null) { + final PyExpression target = forPart.getTarget(); + if (target instanceof PyTargetExpression && element.getText().equals(target.getName())) + return false; + } + final PyStatement nonlocalStatement = + PsiTreeUtil.getParentOfType(element, PyNonlocalStatement.class, PyGlobalStatement.class); + final PyStatementList statementList = + PsiTreeUtil.getParentOfType(element, PyStatementList.class); + PyImportStatement importStatement = PsiTreeUtil.getParentOfType(element, PyImportStatement.class); + return nonlocalStatement == null && importStatement == null && + statementList != null && function != null; + } + + private static boolean isResolvedToParameter(PsiElement element) { while (element instanceof PyReferenceExpression) { final PsiReference reference = element.getReference(); if (reference != null && reference.resolve() instanceof PyNamedParameter) diff --git a/python/src/com/jetbrains/python/run/PythonConfigurationType.java b/python/src/com/jetbrains/python/run/PythonConfigurationType.java index dd1501cf292d..4832f40dad3b 100644 --- a/python/src/com/jetbrains/python/run/PythonConfigurationType.java +++ b/python/src/com/jetbrains/python/run/PythonConfigurationType.java @@ -48,7 +48,7 @@ public class PythonConfigurationType implements ConfigurationType { } public Icon getIcon() { - return PythonIcons.Python.Icons.Python; + return PythonIcons.Python.Python; } public ConfigurationFactory[] getConfigurationFactories() { diff --git a/python/src/com/jetbrains/python/sdk/PythonSdkType.java b/python/src/com/jetbrains/python/sdk/PythonSdkType.java index c42eb430951f..4aaba6f4c176 100644 --- a/python/src/com/jetbrains/python/sdk/PythonSdkType.java +++ b/python/src/com/jetbrains/python/sdk/PythonSdkType.java @@ -94,7 +94,7 @@ public class PythonSdkType extends SdkType { } public Icon getIcon() { - return PythonIcons.Python.Icons.Python; + return PythonIcons.Python.Python; } @NotNull diff --git a/python/src/com/jetbrains/python/sdk/flavors/IronPythonSdkFlavor.java b/python/src/com/jetbrains/python/sdk/flavors/IronPythonSdkFlavor.java index 8e1138db9847..7b3b32d1ba6d 100644 --- a/python/src/com/jetbrains/python/sdk/flavors/IronPythonSdkFlavor.java +++ b/python/src/com/jetbrains/python/sdk/flavors/IronPythonSdkFlavor.java @@ -84,6 +84,6 @@ public class IronPythonSdkFlavor extends PythonSdkFlavor { @Override public Icon getIcon() { - return PythonIcons.Python.Icons.Dotnet; + return PythonIcons.Python.Dotnet; } } diff --git a/python/src/com/jetbrains/python/sdk/flavors/JythonSdkFlavor.java b/python/src/com/jetbrains/python/sdk/flavors/JythonSdkFlavor.java index eca1b1776f99..8a8640481041 100644 --- a/python/src/com/jetbrains/python/sdk/flavors/JythonSdkFlavor.java +++ b/python/src/com/jetbrains/python/sdk/flavors/JythonSdkFlavor.java @@ -66,6 +66,6 @@ public class JythonSdkFlavor extends PythonSdkFlavor { @Override public Icon getIcon() { - return PythonIcons.Python.Icons.Jython; + return PythonIcons.Python.Jython; } } diff --git a/python/src/com/jetbrains/python/sdk/flavors/PyPySdkFlavor.java b/python/src/com/jetbrains/python/sdk/flavors/PyPySdkFlavor.java index a56007fc8e6d..9342d32ecb6f 100644 --- a/python/src/com/jetbrains/python/sdk/flavors/PyPySdkFlavor.java +++ b/python/src/com/jetbrains/python/sdk/flavors/PyPySdkFlavor.java @@ -77,6 +77,6 @@ public class PyPySdkFlavor extends PythonSdkFlavor { @Override public Icon getIcon() { - return PythonIcons.Python.Icons.Pypy; + return PythonIcons.Python.Pypy; } } diff --git a/python/src/com/jetbrains/python/sdk/flavors/PythonSdkFlavor.java b/python/src/com/jetbrains/python/sdk/flavors/PythonSdkFlavor.java index 5fad2e1107c8..000f67ba2d8c 100644 --- a/python/src/com/jetbrains/python/sdk/flavors/PythonSdkFlavor.java +++ b/python/src/com/jetbrains/python/sdk/flavors/PythonSdkFlavor.java @@ -229,6 +229,6 @@ public abstract class PythonSdkFlavor { } public Icon getIcon() { - return PythonIcons.Python.Icons.Python; + return PythonIcons.Python.Python; } } diff --git a/python/src/com/jetbrains/python/sdk/flavors/VirtualEnvSdkFlavor.java b/python/src/com/jetbrains/python/sdk/flavors/VirtualEnvSdkFlavor.java index b3790d2fc1eb..ed48bb673e4a 100644 --- a/python/src/com/jetbrains/python/sdk/flavors/VirtualEnvSdkFlavor.java +++ b/python/src/com/jetbrains/python/sdk/flavors/VirtualEnvSdkFlavor.java @@ -118,6 +118,6 @@ public class VirtualEnvSdkFlavor extends CPythonSdkFlavor { @Override public Icon getIcon() { - return PythonIcons.Python.Icons.Virtualenv; + return PythonIcons.Python.Virtualenv; } } diff --git a/python/src/com/jetbrains/python/structureView/PyStructureViewElement.java b/python/src/com/jetbrains/python/structureView/PyStructureViewElement.java index 66b4fab74450..a976ada169d7 100644 --- a/python/src/com/jetbrains/python/structureView/PyStructureViewElement.java +++ b/python/src/com/jetbrains/python/structureView/PyStructureViewElement.java @@ -275,13 +275,13 @@ public class PyStructureViewElement implements StructureViewTreeElement { icon.setIcon(normal_icon, 0); Icon overlay = null; if (myVisibility == Visibility.PRIVATE || myVisibility == Visibility.PROTECTED) { - overlay = PythonIcons.Python.Icons.Nodes.Lock; + overlay = PythonIcons.Python.Nodes.Lock; } else if (myVisibility == Visibility.PREDEFINED) { - overlay = PythonIcons.Python.Icons.Nodes.Cyan_dot; + overlay = PythonIcons.Python.Nodes.Cyan_dot; } else if (myVisibility == Visibility.INVISIBLE) { - overlay = PythonIcons.Python.Icons.Nodes.Red_inv_triangle; + overlay = PythonIcons.Python.Nodes.Red_inv_triangle; } if (overlay != null) { icon.setIcon(overlay, 1); diff --git a/python/src/com/jetbrains/python/testing/PythonTestConfigurationType.java b/python/src/com/jetbrains/python/testing/PythonTestConfigurationType.java index 3a4de2fbc86c..987c9b2b8544 100644 --- a/python/src/com/jetbrains/python/testing/PythonTestConfigurationType.java +++ b/python/src/com/jetbrains/python/testing/PythonTestConfigurationType.java @@ -121,7 +121,7 @@ public class PythonTestConfigurationType implements ConfigurationType { @Override public Icon getIcon() { - return PythonIcons.Python.Icons.PythonTests; + return PythonIcons.Python.PythonTests; } @NotNull diff --git a/python/testData/deprecation/deprecatedAsFallback.py b/python/testData/deprecation/deprecatedAsFallback.py new file mode 100644 index 000000000000..5302aeca7437 --- /dev/null +++ b/python/testData/deprecation/deprecatedAsFallback.py @@ -0,0 +1,4 @@ +try: + from urlparse import parse_qs, parse_qsl +except ImportError: + from cgi import parse_qs, parse_qsl \ No newline at end of file diff --git a/python/testData/inspections/AugmentAssignmentSubscription.py b/python/testData/inspections/AugmentAssignmentSubscription.py new file mode 100644 index 000000000000..fd57a20495a7 --- /dev/null +++ b/python/testData/inspections/AugmentAssignmentSubscription.py @@ -0,0 +1,3 @@ +current_sum = 1 +numbers = [1, 2, 3] +current_sum = current_sum + numbers[0] \ No newline at end of file diff --git a/python/testData/inspections/AugmentAssignmentSubscription_after.py b/python/testData/inspections/AugmentAssignmentSubscription_after.py new file mode 100644 index 000000000000..30e3c4cc8121 --- /dev/null +++ b/python/testData/inspections/AugmentAssignmentSubscription_after.py @@ -0,0 +1,3 @@ +current_sum = 1 +numbers = [1, 2, 3] +current_sum += numbers[0] \ No newline at end of file diff --git a/python/testData/inspections/PyMissingConstructorInspection/innerClass.py b/python/testData/inspections/PyMissingConstructorInspection/innerClass.py new file mode 100644 index 000000000000..92cc3c83f432 --- /dev/null +++ b/python/testData/inspections/PyMissingConstructorInspection/innerClass.py @@ -0,0 +1,18 @@ + +class Base(object): + def __init__(self, param): + print "Base", param + + +class Wrapper(object): + class Child(Base): + def __init__(self, param1, param2): + # Here PyCharm claims no super call + super(Wrapper.Child, self).__init__(param2) + print "Child", param1 + + def __init__(self): + self.child = self.Child("aaa", "bbb") + + +wrapper = Wrapper() diff --git a/python/testData/intentions/afterConvertTripleQuotedString1.py b/python/testData/intentions/afterConvertTripleQuotedString1.py new file mode 100644 index 000000000000..90c7819ca4e4 --- /dev/null +++ b/python/testData/intentions/afterConvertTripleQuotedString1.py @@ -0,0 +1,3 @@ +s = ("\n" + "my quote\" some text after it\n" +) \ No newline at end of file diff --git a/python/testData/intentions/beforeConvertTripleQuotedString1.py b/python/testData/intentions/beforeConvertTripleQuotedString1.py new file mode 100644 index 000000000000..bc08e8b13fa4 --- /dev/null +++ b/python/testData/intentions/beforeConvertTripleQuotedString1.py @@ -0,0 +1,3 @@ +s = """ +my quote" some text after it +""" \ No newline at end of file diff --git a/python/testData/refactoring/introduceParameter/functionDef.py b/python/testData/refactoring/introduceParameter/functionDef.py new file mode 100644 index 000000000000..61262d42427b --- /dev/null +++ b/python/testData/refactoring/introduceParameter/functionDef.py @@ -0,0 +1,2 @@ +def f(b="myValue"): + pass \ No newline at end of file diff --git a/python/testData/refactoring/introduceParameter/global.py b/python/testData/refactoring/introduceParameter/global.py new file mode 100644 index 000000000000..ac3caa0898a8 --- /dev/null +++ b/python/testData/refactoring/introduceParameter/global.py @@ -0,0 +1,4 @@ +def f2(): + param = 1 + def f(): + global param \ No newline at end of file diff --git a/python/testData/refactoring/introduceParameter/localVariable1.py b/python/testData/refactoring/introduceParameter/localVariable1.py new file mode 100644 index 000000000000..a1c0d883a1af --- /dev/null +++ b/python/testData/refactoring/introduceParameter/localVariable1.py @@ -0,0 +1,3 @@ +def f(): + a = 1 + print a + 3 \ No newline at end of file diff --git a/python/testData/refactoring/introduceParameter/localVariableInFor.py b/python/testData/refactoring/introduceParameter/localVariableInFor.py new file mode 100644 index 000000000000..4b92eea3da06 --- /dev/null +++ b/python/testData/refactoring/introduceParameter/localVariableInFor.py @@ -0,0 +1,2 @@ +for item in range(100): + pass \ No newline at end of file diff --git a/python/testData/refactoring/introduceParameter/localVariableParam.py b/python/testData/refactoring/introduceParameter/localVariableParam.py new file mode 100644 index 000000000000..67011a83d668 --- /dev/null +++ b/python/testData/refactoring/introduceParameter/localVariableParam.py @@ -0,0 +1,2 @@ +def f(b=1): + return b + 1 \ No newline at end of file diff --git a/python/testData/refactoring/introduceParameter/nonLocal.py b/python/testData/refactoring/introduceParameter/nonLocal.py new file mode 100644 index 000000000000..1f42e3c56360 --- /dev/null +++ b/python/testData/refactoring/introduceParameter/nonLocal.py @@ -0,0 +1,4 @@ +def f2(): + param = 1 + def f(): + nonlocal param \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyDeprecationTest.java b/python/testSrc/com/jetbrains/python/PyDeprecationTest.java index abb10de9c0f8..3a63d62acf6f 100644 --- a/python/testSrc/com/jetbrains/python/PyDeprecationTest.java +++ b/python/testSrc/com/jetbrains/python/PyDeprecationTest.java @@ -27,6 +27,12 @@ public class PyDeprecationTest extends PyTestCase { assertNotParsed((PyFile) myFixture.getFile()); } + public void testDeprecatedAsFallback() { + myFixture.enableInspections(PyDeprecationInspection.class); + myFixture.configureByFile("deprecation/deprecatedAsFallback.py"); + myFixture.checkHighlighting(true, false, false); + } + public void testDeprecatedProperty() { myFixture.enableInspections(PyDeprecationInspection.class); myFixture.configureByFile("deprecation/deprecatedProperty.py"); diff --git a/python/testSrc/com/jetbrains/python/PyIntentionTest.java b/python/testSrc/com/jetbrains/python/PyIntentionTest.java index 8d9b82e994e1..6dc0a3cfda75 100644 --- a/python/testSrc/com/jetbrains/python/PyIntentionTest.java +++ b/python/testSrc/com/jetbrains/python/PyIntentionTest.java @@ -237,10 +237,15 @@ public class PyIntentionTest extends PyTestCase { public void testConvertVariadicParam() { //PY-2264 doTest(PyBundle.message("INTN.convert.variadic.param")); } + public void testConvertTripleQuotedString() { //PY-2697 doTest(PyBundle.message("INTN.triple.quoted.string")); } + public void testConvertTripleQuotedString1() { //PY-7774 + doTest(PyBundle.message("INTN.triple.quoted.string")); + } + public void testTransformConditionalExpression() { //PY-3094 doTest(PyBundle.message("INTN.transform.into.if.else.statement")); } diff --git a/python/testSrc/com/jetbrains/python/PyQuickFixTest.java b/python/testSrc/com/jetbrains/python/PyQuickFixTest.java index e0ee6d07c252..84b60a170548 100644 --- a/python/testSrc/com/jetbrains/python/PyQuickFixTest.java +++ b/python/testSrc/com/jetbrains/python/PyQuickFixTest.java @@ -241,6 +241,11 @@ public class PyQuickFixTest extends PyTestCase { PyBundle.message("QFIX.augment.assignment"), true, true); } + public void testAugmentAssignmentSubscription() { // PY-7715 + doInspectionTest("AugmentAssignmentFunction.py", PyAugmentAssignmentInspection.class, + PyBundle.message("QFIX.augment.assignment"), true, true); + } + public void testChainedComparisons() { // PY-1020 doInspectionTest("ChainedComparisons.py", PyChainedComparisonsInspection.class, PyBundle.message("QFIX.chained.comparison"), true, true); diff --git a/python/testSrc/com/jetbrains/python/inspections/PyMissingConstructorTest.java b/python/testSrc/com/jetbrains/python/inspections/PyMissingConstructorTest.java index cf734731f38c..f575647386a7 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyMissingConstructorTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyMissingConstructorTest.java @@ -33,8 +33,11 @@ public class PyMissingConstructorTest extends PyTestCase { doTest(); } - // PY-7176 - public void testException() { + public void testException() { // PY-7176 + doTest(); + } + + public void testInnerClass() { //PY-7699 doTest(); } diff --git a/python/testSrc/com/jetbrains/python/refactoring/PyIntroduceParameterTest.java b/python/testSrc/com/jetbrains/python/refactoring/PyIntroduceParameterTest.java index 19047fc12fea..b31b0fb87048 100644 --- a/python/testSrc/com/jetbrains/python/refactoring/PyIntroduceParameterTest.java +++ b/python/testSrc/com/jetbrains/python/refactoring/PyIntroduceParameterTest.java @@ -3,6 +3,7 @@ package com.jetbrains.python.refactoring; import com.intellij.refactoring.util.CommonRefactoringUtil; import com.intellij.testFramework.TestDataPath; import com.jetbrains.python.PyBundle; +import com.jetbrains.python.psi.LanguageLevel; import com.jetbrains.python.refactoring.introduce.IntroduceHandler; import com.jetbrains.python.refactoring.introduce.parameter.PyIntroduceParameterHandler; @@ -35,6 +36,27 @@ public class PyIntroduceParameterTest extends PyIntroduceTestCase { doTestCannotPerform(PyBundle.message("refactoring.introduce.selection.error")); } + public void testLocalVariable1() { + doTestCannotPerform(PyBundle.message("refactoring.introduce.selection.error")); + } + + public void testLocalVariableParam() { + doTestCannotPerform(PyBundle.message("refactoring.introduce.selection.error")); + } + + public void testNonLocal() { + doTestCannotPerform(PyBundle.message("refactoring.introduce.selection.error"), LanguageLevel.PYTHON32); + } + + public void testGlobal() { + doTestCannotPerform(PyBundle.message("refactoring.introduce.selection.error")); + } + + public void testFunctionDef() { + doTestCannotPerform(PyBundle.message("refactoring.introduce.selection.error")); + } + + @Override protected String getTestDataPath() { return super.getTestDataPath() + "/refactoring/introduceParameter"; @@ -52,4 +74,14 @@ public class PyIntroduceParameterTest extends PyIntroduceTestCase { assertEquals(expected, e.getMessage()); } } + + private void doTestCannotPerform(String expected, LanguageLevel languageLevel) { + setLanguageLevel(languageLevel); + try { + doTestCannotPerform(expected); + } + finally { + setLanguageLevel(null); + } + } }