diff --git a/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java b/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java index 324e511fccc4..31eef1c293e5 100644 --- a/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java @@ -204,8 +204,7 @@ public class PyCompatibilityInspection extends PyInspection { registerForAllMatchingVersions(level -> unsupportedMethods.getOrDefault(level, Collections.emptySet()).contains(functionName), " not have method " + functionName, - node, - null); + node); } } @@ -215,8 +214,7 @@ public class PyCompatibilityInspection extends PyInspection { !myUsedImports.contains(functionName)) { registerForAllMatchingVersions(level -> UnsupportedFeaturesUtil.BUILTINS.get(level).contains(functionName), " not have method " + functionName, - node, - null); + node); } } else if (resolvedCallee instanceof PyTargetExpression) { @@ -227,8 +225,7 @@ public class PyCompatibilityInspection extends PyInspection { PyBuiltinCache.getInstance(resolvedCallee).isBuiltin(resolvedCallee)) { registerForAllMatchingVersions(level -> UnsupportedFeaturesUtil.BUILTINS.get(level).contains(PyNames.TYPE_LONG), " not have type long. Use int instead.", - node, - null); + node); } } } @@ -256,8 +253,7 @@ public class PyCompatibilityInspection extends PyInspection { registerForAllMatchingVersions(level -> UnsupportedFeaturesUtil.MODULES.get(level).contains(moduleName) && !BACKPORTED_PACKAGES.contains(moduleName), " not have module " + moduleName, - importElement, - null); + importElement); } } @@ -287,8 +283,7 @@ public class PyCompatibilityInspection extends PyInspection { registerForAllMatchingVersions(level -> UnsupportedFeaturesUtil.MODULES.get(level).contains(moduleName) && !BACKPORTED_PACKAGES.contains(moduleName), " not have module " + name, - source, - null); + source); } } @@ -364,14 +359,19 @@ public class PyCompatibilityInspection extends PyInspection { warnAsyncAndAwaitAreBecomingKeywordsInPy37(node); } + @Override + protected boolean registerForLanguageLevel(@NotNull LanguageLevel level) { + return level != LanguageLevel.forElement(myHolder.getFile()); + } + private void warnAsyncAndAwaitAreBecomingKeywordsInPy37(@NotNull PsiNameIdentifierOwner nameIdentifierOwner) { final PsiElement nameIdentifier = nameIdentifierOwner.getNameIdentifier(); if (nameIdentifier != null && ArrayUtil.contains(nameIdentifierOwner.getName(), PyNames.AWAIT, PyNames.ASYNC) && LanguageLevel.forElement(nameIdentifierOwner).isOlderThan(LanguageLevel.PYTHON37)) { - registerOnFirstMatchingVersion(level -> level.isAtLeast(LanguageLevel.PYTHON37), - "'async' and 'await' are keywords in Python 3.7 and newer", + registerForAllMatchingVersions(level -> level.isAtLeast(LanguageLevel.PYTHON37), + " not allow 'async' and 'await' as names", nameIdentifier, new PyRenameElementQuickFix(nameIdentifierOwner)); } diff --git a/python/src/com/jetbrains/python/validation/CompatibilityVisitor.java b/python/src/com/jetbrains/python/validation/CompatibilityVisitor.java index e8acbb991e62..a71621836023 100644 --- a/python/src/com/jetbrains/python/validation/CompatibilityVisitor.java +++ b/python/src/com/jetbrains/python/validation/CompatibilityVisitor.java @@ -57,10 +57,9 @@ public abstract class CompatibilityVisitor extends PyAnnotator { public void visitPyAnnotation(PyAnnotation node) { final PsiElement parent = node.getParent(); if (!(parent instanceof PyFunction || parent instanceof PyNamedParameter)) { - registerForAllMatchingVersions(level -> level.isOlderThan(LanguageLevel.PYTHON36), + registerForAllMatchingVersions(level -> level.isOlderThan(LanguageLevel.PYTHON36) && registerForLanguageLevel(level), " not support variable annotations", - node, - null); + node); } } @@ -68,7 +67,7 @@ public abstract class CompatibilityVisitor extends PyAnnotator { public void visitPyDictCompExpression(PyDictCompExpression node) { super.visitPyDictCompExpression(node); - registerForAllMatchingVersions(level -> !level.supportsSetLiterals(), + registerForAllMatchingVersions(level -> !level.supportsSetLiterals() && registerForLanguageLevel(level), " not support dictionary comprehensions", node, new ConvertDictCompQuickFix(), @@ -79,7 +78,7 @@ public abstract class CompatibilityVisitor extends PyAnnotator { public void visitPySetLiteralExpression(PySetLiteralExpression node) { super.visitPySetLiteralExpression(node); - registerForAllMatchingVersions(level -> !level.supportsSetLiterals(), + registerForAllMatchingVersions(level -> !level.supportsSetLiterals() && registerForLanguageLevel(level), " not support set literal expressions", node, new ConvertSetLiteralQuickFix(), @@ -90,7 +89,7 @@ public abstract class CompatibilityVisitor extends PyAnnotator { public void visitPySetCompExpression(PySetCompExpression node) { super.visitPySetCompExpression(node); - registerForAllMatchingVersions(level -> !level.supportsSetLiterals(), + registerForAllMatchingVersions(level -> !level.supportsSetLiterals() && registerForLanguageLevel(level), " not support set comprehensions", node, null, @@ -109,7 +108,10 @@ public abstract class CompatibilityVisitor extends PyAnnotator { } if (element != null && ",".equals(element.getText())) { - registerForAllMatchingVersions(LanguageLevel::isPy3K, " not support this syntax.", node, new ReplaceExceptPartQuickFix()); + registerForAllMatchingVersions(level -> level.isPy3K() && registerForLanguageLevel(level), + " not support this syntax.", + node, + new ReplaceExceptPartQuickFix()); } } } @@ -126,10 +128,16 @@ public abstract class CompatibilityVisitor extends PyAnnotator { if (qName != null) { if (qName.matches("builtins")) { - registerForAllMatchingVersions(LanguageLevel::isPython2, " not have module builtins", node, new ReplaceBuiltinsQuickFix()); + registerForAllMatchingVersions(level -> level.isPython2() && registerForLanguageLevel(level), + " not have module builtins", + node, + new ReplaceBuiltinsQuickFix()); } else if (qName.matches("__builtin__")) { - registerForAllMatchingVersions(LanguageLevel::isPy3K, " not have module __builtin__", node, new ReplaceBuiltinsQuickFix()); + registerForAllMatchingVersions(level -> level.isPy3K() && registerForLanguageLevel(level), + " not have module __builtin__", + node, + new ReplaceBuiltinsQuickFix()); } } } @@ -140,14 +148,14 @@ public abstract class CompatibilityVisitor extends PyAnnotator { super.visitPyStarExpression(node); if (node.isAssignmentTarget()) { - registerOnFirstMatchingVersion(LanguageLevel::isPython2, - "Python versions < 3.0 do not support starred expressions as assignment targets", + registerForAllMatchingVersions(level -> level.isPython2() && registerForLanguageLevel(level), + " not support starred expressions as assignment targets", node); } if (node.isUnpacking()) { - registerOnFirstMatchingVersion(level -> level.isOlderThan(LanguageLevel.PYTHON35), - "Python versions < 3.5 do not support starred expressions in tuples, lists, and sets", + registerForAllMatchingVersions(level -> level.isOlderThan(LanguageLevel.PYTHON35) && registerForLanguageLevel(level), + " not support starred expressions in tuples, lists, and sets", node); } } @@ -156,8 +164,8 @@ public abstract class CompatibilityVisitor extends PyAnnotator { public void visitPyDoubleStarExpression(PyDoubleStarExpression node) { super.visitPyDoubleStarExpression(node); - registerOnFirstMatchingVersion(level -> level.isOlderThan(LanguageLevel.PYTHON35), - "Python versions < 3.5 do not support starred expressions in dicts", + registerForAllMatchingVersions(level -> level.isOlderThan(LanguageLevel.PYTHON35) && registerForLanguageLevel(level), + " not support starred expressions in dicts", node); } @@ -166,7 +174,10 @@ public abstract class CompatibilityVisitor extends PyAnnotator { super.visitPyBinaryExpression(node); if (node.isOperator("<>")) { - registerForAllMatchingVersions(LanguageLevel::isPy3K, " not support <>, use != instead.", node, new ReplaceNotEqOperatorQuickFix()); + registerForAllMatchingVersions(level -> level.isPy3K() && registerForLanguageLevel(level), + " not support <>, use != instead.", + node, + new ReplaceNotEqOperatorQuickFix()); } else if (node.isOperator("@")) { checkMatrixMultiplicationOperator(node.getPsiOperator()); @@ -174,8 +185,8 @@ public abstract class CompatibilityVisitor extends PyAnnotator { } private void checkMatrixMultiplicationOperator(PsiElement node) { - registerOnFirstMatchingVersion(level -> level.isOlderThan(LanguageLevel.PYTHON35), - "Python versions < 3.5 do not support matrix multiplication operators", + registerForAllMatchingVersions(level -> level.isOlderThan(LanguageLevel.PYTHON35) && registerForLanguageLevel(level), + " not support matrix multiplication operators", node); } @@ -187,7 +198,7 @@ public abstract class CompatibilityVisitor extends PyAnnotator { if (node.isIntegerLiteral()) { if (text.endsWith("l") || text.endsWith("L")) { - registerForAllMatchingVersions(LanguageLevel::isPy3K, + registerForAllMatchingVersions(level -> level.isPy3K() && registerForLanguageLevel(level), " not support a trailing \'l\' or \'L\'.", node, new RemoveTrailingLQuickFix()); @@ -196,7 +207,7 @@ public abstract class CompatibilityVisitor extends PyAnnotator { if (text.length() > 1 && text.charAt(0) == '0') { final char secondChar = Character.toLowerCase(text.charAt(1)); if (secondChar != 'o' && secondChar != 'b' && secondChar != 'x' && text.chars().anyMatch(c -> c != '0')) { - registerForAllMatchingVersions(LanguageLevel::isPy3K, + registerForAllMatchingVersions(level -> level.isPy3K() && registerForLanguageLevel(level), " not support this syntax. It requires '0o' prefix for octal literals", node, new ReplaceOctalNumericLiteralQuickFix()); @@ -205,7 +216,7 @@ public abstract class CompatibilityVisitor extends PyAnnotator { } if (text.contains("_")) { - registerForAllMatchingVersions(level -> level.isOlderThan(LanguageLevel.PYTHON36), + registerForAllMatchingVersions(level -> level.isOlderThan(LanguageLevel.PYTHON36) && registerForLanguageLevel(level), " not support underscores in numeric literals", node, new PyRemoveUnderscoresInNumericLiteralsQuickFix()); @@ -227,7 +238,7 @@ public abstract class CompatibilityVisitor extends PyAnnotator { seenNonBytes |= !bytes; final int elementStart = element.getTextOffset(); - registerForAllMatchingVersions(level -> !getSupportedStringPrefixes(level).contains(prefix), + registerForAllMatchingVersions(level -> !getSupportedStringPrefixes(level).contains(prefix) && registerForLanguageLevel(level), " not support a '" + prefix + "' prefix", node, TextRange.create(elementStart, elementStart + element.getPrefixLength()), @@ -236,10 +247,9 @@ public abstract class CompatibilityVisitor extends PyAnnotator { } if (seenBytes && seenNonBytes) { - registerForAllMatchingVersions(LanguageLevel::isPy3K, + registerForAllMatchingVersions(level -> level.isPy3K() && registerForLanguageLevel(level), " not allow to mix bytes and non-bytes literals", - node, - null); + node); } } @@ -260,11 +270,12 @@ public abstract class CompatibilityVisitor extends PyAnnotator { public void visitPyListCompExpression(final PyListCompExpression node) { super.visitPyListCompExpression(node); - final List nodes = node.getForComponents().stream().map(PyComprehensionForComponent::getIteratedList).collect(Collectors.toList()); - registerForAllMatchingVersions(level -> UnsupportedFeaturesUtil.visitPyListCompExpression(node, level), - " not support this syntax in list comprehensions.", - nodes, - new ReplaceListComprehensionsQuickFix()); + registerForAllMatchingVersions( + level -> registerForLanguageLevel(level) && UnsupportedFeaturesUtil.visitPyListCompExpression(node, level), + " not support this syntax in list comprehensions.", + ContainerUtil.map(node.getForComponents(), PyComprehensionForComponent::getIteratedList), + new ReplaceListComprehensionsQuickFix() + ); } @Override @@ -272,19 +283,20 @@ public abstract class CompatibilityVisitor extends PyAnnotator { super.visitPyRaiseStatement(node); // empty raise under finally - registerForAllMatchingVersions(level -> UnsupportedFeaturesUtil.raiseHasNoArgsUnderFinally(node, level), - " not support this syntax. Raise with no arguments can only be used in an except block", - node, - null); + registerForAllMatchingVersions( + level -> registerForLanguageLevel(level) && UnsupportedFeaturesUtil.raiseHasNoArgsUnderFinally(node, level), + " not support this syntax. Raise with no arguments can only be used in an except block", + node + ); // raise 1, 2, 3 - registerForAllMatchingVersions(level -> UnsupportedFeaturesUtil.raiseHasMoreThenOneArg(node, level), + registerForAllMatchingVersions(level -> registerForLanguageLevel(level) && UnsupportedFeaturesUtil.raiseHasMoreThenOneArg(node, level), " not support this syntax.", node, new ReplaceRaiseStatementQuickFix()); // raise exception from cause - registerForAllMatchingVersions(level -> UnsupportedFeaturesUtil.raiseHasFromKeyword(node, level), + registerForAllMatchingVersions(level -> registerForLanguageLevel(level) && UnsupportedFeaturesUtil.raiseHasFromKeyword(node, level), " not support this syntax.", node, new ReplaceRaiseStatementQuickFix()); @@ -294,7 +306,7 @@ public abstract class CompatibilityVisitor extends PyAnnotator { public void visitPyReprExpression(PyReprExpression node) { super.visitPyReprExpression(node); - registerForAllMatchingVersions(LanguageLevel::isPy3K, + registerForAllMatchingVersions(level -> level.isPy3K() && registerForLanguageLevel(level), " not support backquotes, use repr() instead", node, new ReplaceBackquoteExpressionQuickFix()); @@ -307,7 +319,7 @@ public abstract class CompatibilityVisitor extends PyAnnotator { final PyWithItem[] items = node.getWithItems(); if (items.length > 1) { - registerForAllMatchingVersions(level -> !level.supportsSetLiterals(), + registerForAllMatchingVersions(level -> !level.supportsSetLiterals() && registerForLanguageLevel(level), " not support multiple context managers", Arrays.asList(items).subList(1, items.length), null); @@ -331,8 +343,8 @@ public abstract class CompatibilityVisitor extends PyAnnotator { element -> !(element instanceof PyParenthesizedExpression || element instanceof PyTupleExpression); if (arguments.length == 0 || Arrays.stream(arguments).anyMatch(nonParenthesesPredicate)) { - registerOnFirstMatchingVersion(LanguageLevel::isPy3K, - "Python version >= 3.0 do not support this syntax. " + + registerForAllMatchingVersions(level -> level.isPy3K() && registerForLanguageLevel(level), + " not support this syntax. " + "The print statement has been replaced with a print() function", node, new CompatibilityPrintCallQuickFix()); @@ -345,10 +357,9 @@ public abstract class CompatibilityVisitor extends PyAnnotator { final PsiElement firstChild = node.getFirstChild(); if (firstChild != null && PyNames.SUPER.equals(firstChild.getText()) && ArrayUtil.isEmpty(node.getArguments())) { - registerForAllMatchingVersions(LanguageLevel::isPython2, + registerForAllMatchingVersions(level -> level.isPython2() && registerForLanguageLevel(level), " not support this syntax. super() should have arguments in Python 2", - node, - null); + node); } highlightIncorrectArguments(node); @@ -365,8 +376,8 @@ public abstract class CompatibilityVisitor extends PyAnnotator { super.visitPyPrefixExpression(node); if (node.getOperator() == PyTokenTypes.AWAIT_KEYWORD) { - registerOnFirstMatchingVersion(level -> level.isOlderThan(LanguageLevel.PYTHON35), - "Python versions < 3.5 do not support this syntax", + registerForAllMatchingVersions(level -> level.isOlderThan(LanguageLevel.PYTHON35) && registerForLanguageLevel(level), + " not support this syntax", node); } } @@ -381,7 +392,9 @@ public abstract class CompatibilityVisitor extends PyAnnotator { .filter(function -> function.isAsync() && function.isAsyncAllowed()) .ifPresent( function -> { - if (!node.isDelegating() && myVersionsToProcess.contains(LanguageLevel.PYTHON35)) { + if (!node.isDelegating() && + registerForLanguageLevel(LanguageLevel.PYTHON35) && + myVersionsToProcess.contains(LanguageLevel.PYTHON35)) { registerProblem(node, "Python version 3.5 does not support 'yield' inside async functions"); } } @@ -391,15 +404,15 @@ public abstract class CompatibilityVisitor extends PyAnnotator { return; } - registerOnFirstMatchingVersion(LanguageLevel::isPython2, - "Python versions < 3.3 do not support this syntax. Delegating to a subgenerator is available since " + + registerForAllMatchingVersions(level -> level.isPython2() && registerForLanguageLevel(level), + " not support this syntax. Delegating to a subgenerator is available since " + "Python 3.3; use explicit iteration over subgenerator instead.", node); } @Override public void visitPyReturnStatement(PyReturnStatement node) { - if (ContainerUtil.exists(myVersionsToProcess, LanguageLevel::isPython2)) { + if (ContainerUtil.exists(myVersionsToProcess, level -> level.isPython2() && registerForLanguageLevel(level))) { final PyFunction function = PsiTreeUtil.getParentOfType(node, PyFunction.class, false, PyClass.class); if (function != null && node.getExpression() != null) { final YieldVisitor visitor = new YieldVisitor(); @@ -422,8 +435,8 @@ public abstract class CompatibilityVisitor extends PyAnnotator { if (sliceItem != null) { return; } - registerOnFirstMatchingVersion(LanguageLevel::isPython2, - "Python versions < 3.0 do not support '...' outside of sequence slicings.", + registerForAllMatchingVersions(level -> level.isPython2() && registerForLanguageLevel(level), + " not support '...' outside of sequence slicings.", node); } } @@ -443,11 +456,12 @@ public abstract class CompatibilityVisitor extends PyAnnotator { private void checkAsyncKeyword(@NotNull PsiElement node) { final ASTNode asyncNode = node.getNode().findChildByType(PyTokenTypes.ASYNC_KEYWORD); if (asyncNode != null) { - registerOnFirstMatchingVersion(level -> level.isOlderThan(LanguageLevel.PYTHON35), - "Python versions < 3.5 do not support this syntax", + registerForAllMatchingVersions(level -> level.isOlderThan(LanguageLevel.PYTHON35) && registerForLanguageLevel(level), + " not support this syntax", node, asyncNode.getTextRange(), - null); + null, + true); } } @@ -476,6 +490,10 @@ public abstract class CompatibilityVisitor extends PyAnnotator { } } + protected boolean registerForLanguageLevel(@NotNull LanguageLevel level) { + return true; + } + protected abstract void registerProblem(@NotNull PsiElement node, @NotNull TextRange range, @NotNull String message, @@ -544,35 +562,20 @@ public abstract class CompatibilityVisitor extends PyAnnotator { @NotNull String suffix, @NotNull PsiElement node, @Nullable LocalQuickFix localQuickFix) { - registerForAllMatchingVersions(levelPredicate, suffix, node, node.getTextRange(), localQuickFix, true); + registerForAllMatchingVersions(levelPredicate, suffix, node, localQuickFix, true); } - protected void registerOnFirstMatchingVersion(@NotNull Predicate levelPredicate, - @NotNull String message, - @NotNull PsiElement node, - @NotNull TextRange range, - @Nullable LocalQuickFix localQuickFix) { - if (myVersionsToProcess.stream().anyMatch(levelPredicate)) { - registerProblem(node, range, message, localQuickFix, true); - } - } - - protected void registerOnFirstMatchingVersion(@NotNull Predicate levelPredicate, - @NotNull String message, - @NotNull PsiElement node, - @Nullable LocalQuickFix localQuickFix) { - registerOnFirstMatchingVersion(levelPredicate, message, node, node.getTextRange(), localQuickFix); - } - - protected void registerOnFirstMatchingVersion(@NotNull Predicate levelPredicate, - @NotNull String message, + protected void registerForAllMatchingVersions(@NotNull Predicate levelPredicate, + @NotNull String suffix, @NotNull PsiElement node) { - registerOnFirstMatchingVersion(levelPredicate, message, node, node.getTextRange(), null); + registerForAllMatchingVersions(levelPredicate, suffix, node, null, true); } @Override public void visitPyNonlocalStatement(final PyNonlocalStatement node) { - registerOnFirstMatchingVersion(LanguageLevel::isPython2, "nonlocal keyword available only since py3", node); + registerForAllMatchingVersions(level -> level.isPython2() && registerForLanguageLevel(level), + " not have nonlocal keyword", + node); } private void highlightIncorrectArguments(@NotNull PyCallExpression callExpression) { @@ -590,8 +593,8 @@ public abstract class CompatibilityVisitor extends PyAnnotator { registerProblem(argument, "Keyword argument repeated", new PyRemoveArgumentQuickFix()); } else if (seenKeywordContainer) { - registerOnFirstMatchingVersion(level -> level.isOlderThan(LanguageLevel.PYTHON35), - "Python versions < 3.5 do not allow keyword arguments after **expression", + registerForAllMatchingVersions(level -> level.isOlderThan(LanguageLevel.PYTHON35) && registerForLanguageLevel(level), + " not allow keyword arguments after **expression", argument, new PyRemoveArgumentQuickFix()); } @@ -603,8 +606,8 @@ public abstract class CompatibilityVisitor extends PyAnnotator { final PyStarArgument starArgument = (PyStarArgument)argument; if (starArgument.isKeyword()) { if (seenKeywordContainer) { - registerOnFirstMatchingVersion(level -> level.isOlderThan(LanguageLevel.PYTHON35), - "Python versions < 3.5 do not allow duplicate **expressions", + registerForAllMatchingVersions(level -> level.isOlderThan(LanguageLevel.PYTHON35) && registerForLanguageLevel(level), + " not allow duplicate **expressions", argument, new PyRemoveArgumentQuickFix()); } @@ -612,8 +615,8 @@ public abstract class CompatibilityVisitor extends PyAnnotator { } else { if (seenPositionalContainer) { - registerOnFirstMatchingVersion(level -> level.isOlderThan(LanguageLevel.PYTHON35), - "Python versions < 3.5 do not allow duplicate *expressions", + registerForAllMatchingVersions(level -> level.isOlderThan(LanguageLevel.PYTHON35) && registerForLanguageLevel(level), + " not allow duplicate *expressions", argument, new PyRemoveArgumentQuickFix()); } @@ -625,8 +628,8 @@ public abstract class CompatibilityVisitor extends PyAnnotator { registerProblem(argument, "Positional argument after keyword argument", new PyRemoveArgumentQuickFix()); } else if (seenPositionalContainer) { - registerOnFirstMatchingVersion(level -> level.isOlderThan(LanguageLevel.PYTHON35), - "Python versions < 3.5 do not allow positional arguments after *expression", + registerForAllMatchingVersions(level -> level.isOlderThan(LanguageLevel.PYTHON35) && registerForLanguageLevel(level), + " not allow positional arguments after *expression", argument, new PyRemoveArgumentQuickFix()); } @@ -642,8 +645,8 @@ public abstract class CompatibilityVisitor extends PyAnnotator { PsiElement sibling = PyPsiUtils.getNextNonWhitespaceSibling(lastArg); if (sibling != null && sibling.getNode().getElementType() == PyTokenTypes.COMMA) { boolean isKeyword = ((PyStarArgument)lastArg).isKeyword(); - registerOnFirstMatchingVersion(level -> level.isOlderThan(LanguageLevel.PYTHON35), - "Python versions < 3.5 do not allow a trailing comma after " + registerForAllMatchingVersions(level -> level.isOlderThan(LanguageLevel.PYTHON35) && registerForLanguageLevel(level), + " not allow a trailing comma after " + (isKeyword ? "**" : "*") + "expression", sibling); } @@ -654,7 +657,7 @@ public abstract class CompatibilityVisitor extends PyAnnotator { public void visitPyComprehensionElement(PyComprehensionElement node) { super.visitPyComprehensionElement(node); - if (myVersionsToProcess.contains(LanguageLevel.PYTHON35)) { + if (registerForLanguageLevel(LanguageLevel.PYTHON35) && myVersionsToProcess.contains(LanguageLevel.PYTHON35)) { Arrays .stream(node.getNode().getChildren(TokenSet.create(PyTokenTypes.ASYNC_KEYWORD))) .filter(Objects::nonNull) diff --git a/python/testData/inspections/PyArgumentListInspection/parameterWithDefaultAfterKeywordContainer.py b/python/testData/inspections/PyArgumentListInspection/parameterWithDefaultAfterKeywordContainer.py index 23bcd58bdce2..1f1491667127 100644 --- a/python/testData/inspections/PyArgumentListInspection/parameterWithDefaultAfterKeywordContainer.py +++ b/python/testData/inspections/PyArgumentListInspection/parameterWithDefaultAfterKeywordContainer.py @@ -2,4 +2,4 @@ def foo(**kwargs): pass two = 0 kw = {} -foo(**kw, two=1) +foo(**kw, two=1) diff --git a/python/testData/inspections/PyArgumentListInspection/parameterWithDefaultAfterKeywordContainer2.py b/python/testData/inspections/PyArgumentListInspection/parameterWithDefaultAfterKeywordContainer2.py index 8872a9e99666..a32d1c6d671c 100644 --- a/python/testData/inspections/PyArgumentListInspection/parameterWithDefaultAfterKeywordContainer2.py +++ b/python/testData/inspections/PyArgumentListInspection/parameterWithDefaultAfterKeywordContainer2.py @@ -7,4 +7,4 @@ class Foo(object): @classmethod def test(cls): - cls(**kwargs, foo=1) \ No newline at end of file + cls(**kwargs, foo=1) \ No newline at end of file diff --git a/python/testData/inspections/PyArgumentListInspection/py1268.py b/python/testData/inspections/PyArgumentListInspection/py1268.py index baaa9fd9e496..35d0fd6ed3f7 100644 --- a/python/testData/inspections/PyArgumentListInspection/py1268.py +++ b/python/testData/inspections/PyArgumentListInspection/py1268.py @@ -19,7 +19,7 @@ def f2(a, b, c=1, *d): f2(c=3, *(1,2)) f2(1,2,3, *(1,2)) f2(*(1,2), c=20) -f2(*(1,2), 20) # fail: positional past * +f2(*(1,2), 20) # fail: positional past * def f3(a=1, b=2, c=3, *d): return a,b,c,d diff --git a/python/testData/inspections/PyCompatibilityInspection/argumentsUnpackingGeneralizations.py b/python/testData/inspections/PyCompatibilityInspection/argumentsUnpackingGeneralizations.py index d2b2c7012b09..3558259797e7 100644 --- a/python/testData/inspections/PyCompatibilityInspection/argumentsUnpackingGeneralizations.py +++ b/python/testData/inspections/PyCompatibilityInspection/argumentsUnpackingGeneralizations.py @@ -4,14 +4,14 @@ def foo(*args, **kwargs): foo(0, *[1], - 2, - *[3], - 4, + 2, + *[3], + 4, a='a', - *[6], + *[6], b='b', - *[7], + *[7], c='c', **{'d': 'd'}, - e='e', - **{'f': 'f'}) + e='e', + **{'f': 'f'}) diff --git a/python/testData/inspections/PyCompatibilityInspection/asyncAwait.py b/python/testData/inspections/PyCompatibilityInspection/asyncAwait.py index fb26d141fc21..eada4910789f 100644 --- a/python/testData/inspections/PyCompatibilityInspection/asyncAwait.py +++ b/python/testData/inspections/PyCompatibilityInspection/asyncAwait.py @@ -1,7 +1,7 @@ -async def foo(x): - async with x: - y = await x - if await y: - return await z - async for y in x: +async def foo(x): + async with x: + y = await x + if await y: + return await z + async for y in x: pass diff --git a/python/testData/inspections/PyCompatibilityInspection/asyncComprehensions.py b/python/testData/inspections/PyCompatibilityInspection/asyncComprehensions.py index 4cbdd8ba201c..bd2da0d56019 100644 --- a/python/testData/inspections/PyCompatibilityInspection/asyncComprehensions.py +++ b/python/testData/inspections/PyCompatibilityInspection/asyncComprehensions.py @@ -1,6 +1,6 @@ -async def asyncgen(): +async def asyncgen(): yield 10 -async def run(): +async def run(): {i async for i in asyncgen()} [i async for i in asyncgen()] {i: i ** 2 async for i in asyncgen()} diff --git a/python/testData/inspections/PyCompatibilityInspection/awaitInComprehensions.py b/python/testData/inspections/PyCompatibilityInspection/awaitInComprehensions.py index db819f754bd4..3c22098d1981 100644 --- a/python/testData/inspections/PyCompatibilityInspection/awaitInComprehensions.py +++ b/python/testData/inspections/PyCompatibilityInspection/awaitInComprehensions.py @@ -1,16 +1,16 @@ -async def async2(): - [await fun() for fun in funcs] - {await fun() for fun in funcs} - {fun: await fun() for fun in funcs} +async def async2(): + [await fun() for fun in funcs] + {await fun() for fun in funcs} + {fun: await fun() for fun in funcs} - [await fun() for fun in funcs if await smth] - {await fun() for fun in funcs if await smth} - {fun: await fun() for fun in funcs if await smth} + [await fun() for fun in funcs if await smth] + {await fun() for fun in funcs if await smth} + {fun: await fun() for fun in funcs if await smth} - [await fun() async for fun in funcs] - {await fun() async for fun in funcs} - {fun: await fun() async for fun in funcs} + [await fun() async for fun in funcs] + {await fun() async for fun in funcs} + {fun: await fun() async for fun in funcs} - [await fun() async for fun in funcs if await smth] - {await fun() async for fun in funcs if await smth} - {fun: await fun() async for fun in funcs if await smth} \ No newline at end of file + [await fun() async for fun in funcs if await smth] + {await fun() async for fun in funcs if await smth} + {fun: await fun() async for fun in funcs if await smth} \ No newline at end of file diff --git a/python/testData/inspections/PyCompatibilityInspection/doubleStarUnpacking.py b/python/testData/inspections/PyCompatibilityInspection/doubleStarUnpacking.py index 854a89e53db4..0ee45319ece6 100644 --- a/python/testData/inspections/PyCompatibilityInspection/doubleStarUnpacking.py +++ b/python/testData/inspections/PyCompatibilityInspection/doubleStarUnpacking.py @@ -1,2 +1,2 @@ xs = {1: 2} -ys = {**xs, 3: 4} +ys = {**xs, 3: 4} diff --git a/python/testData/inspections/PyCompatibilityInspection/ellipsisAsStatementPy2.py b/python/testData/inspections/PyCompatibilityInspection/ellipsisAsStatementPy2.py index 6e4f90cd7034..b996e0088cab 100644 --- a/python/testData/inspections/PyCompatibilityInspection/ellipsisAsStatementPy2.py +++ b/python/testData/inspections/PyCompatibilityInspection/ellipsisAsStatementPy2.py @@ -1,2 +1,2 @@ def foo(): - ... + ... diff --git a/python/testData/inspections/PyCompatibilityInspection/importStatement.py b/python/testData/inspections/PyCompatibilityInspection/importStatement.py index 5eb2879825e0..16eb6147c229 100644 --- a/python/testData/inspections/PyCompatibilityInspection/importStatement.py +++ b/python/testData/inspections/PyCompatibilityInspection/importStatement.py @@ -1,3 +1,3 @@ -import builtins +import builtins import __builtin__ \ No newline at end of file diff --git a/python/testData/inspections/PyCompatibilityInspection/matMul.py b/python/testData/inspections/PyCompatibilityInspection/matMul.py index d67dcc2221f8..a6c05ef126a6 100644 --- a/python/testData/inspections/PyCompatibilityInspection/matMul.py +++ b/python/testData/inspections/PyCompatibilityInspection/matMul.py @@ -1,2 +1,2 @@ -x @ y -x @= y +x @ y +x @= y diff --git a/python/testData/inspections/PyCompatibilityInspection/printStatement.py b/python/testData/inspections/PyCompatibilityInspection/printStatement.py index 62681a44e44d..7448f586cdcb 100644 --- a/python/testData/inspections/PyCompatibilityInspection/printStatement.py +++ b/python/testData/inspections/PyCompatibilityInspection/printStatement.py @@ -1 +1 @@ -print "One value" \ No newline at end of file +print "One value" \ No newline at end of file diff --git a/python/testData/inspections/PyCompatibilityInspection/starExpression.py b/python/testData/inspections/PyCompatibilityInspection/starExpression.py index 7e89b2a176e8..a42ade5e4ee5 100644 --- a/python/testData/inspections/PyCompatibilityInspection/starExpression.py +++ b/python/testData/inspections/PyCompatibilityInspection/starExpression.py @@ -1,2 +1,2 @@ -t = (1, *(2, 3)) -a, *b, c = t +t = (1, *(2, 3)) +a, *b, c = t diff --git a/python/testData/inspections/PyCompatibilityInspection/stringLiteralExpression.py b/python/testData/inspections/PyCompatibilityInspection/stringLiteralExpression.py index 87b3bb64e75f..834cba79b690 100644 --- a/python/testData/inspections/PyCompatibilityInspection/stringLiteralExpression.py +++ b/python/testData/inspections/PyCompatibilityInspection/stringLiteralExpression.py @@ -2,22 +2,22 @@ a = u"String" # Python 3.6 -a = f"" -a = F"" -a = rf"" -a = fr"" -a = fu"" -a = uf"" -a = bf"" -a = fb"" -a = ufr"" +a = f"" +a = F"" +a = rf"" +a = fr"" +a = fu"" +a = uf"" +a = bf"" +a = fb"" +a = ufr"" # python 3.3 a = u"" a = r"" a = b"" -a = rb"" +a = rb"" a = br"" # python 3.2, 3.1 @@ -48,9 +48,9 @@ a = u"" b"" b = r"" b"" -b = f"" b"" +b = f"" b"" # never was available -a = rr"" -a = bb"" -a = uu"" \ No newline at end of file +a = rr"" +a = bb"" +a = uu"" \ No newline at end of file diff --git a/python/testData/inspections/PyCompatibilityInspection/trailingCommaAfterStarArgs.py b/python/testData/inspections/PyCompatibilityInspection/trailingCommaAfterStarArgs.py index b89e190eb4e5..3c225470b709 100644 --- a/python/testData/inspections/PyCompatibilityInspection/trailingCommaAfterStarArgs.py +++ b/python/testData/inspections/PyCompatibilityInspection/trailingCommaAfterStarArgs.py @@ -2,5 +2,5 @@ def foo(*args, **kwargs): print(args, kwargs) -foo(1, 2, 3, *[3],) -foo(1, 2, 3, *[3], **{'d': 'd'},) +foo(1, 2, 3, *[3],) +foo(1, 2, 3, *[3], **{'d': 'd'},) diff --git a/python/testData/inspections/PyCompatibilityInspection/tryFinallyEmptyRaisePy2.py b/python/testData/inspections/PyCompatibilityInspection/tryFinallyEmptyRaisePy2.py index f72e482d9c54..896a230820a8 100644 --- a/python/testData/inspections/PyCompatibilityInspection/tryFinallyEmptyRaisePy2.py +++ b/python/testData/inspections/PyCompatibilityInspection/tryFinallyEmptyRaisePy2.py @@ -1,4 +1,4 @@ try: raise ValueError finally: - raise \ No newline at end of file + raise \ No newline at end of file diff --git a/python/testData/inspections/PyCompatibilityInspection/underscoresInNumericLiterals.py b/python/testData/inspections/PyCompatibilityInspection/underscoresInNumericLiterals.py index 6c995012c3ef..bccf1478ab42 100644 --- a/python/testData/inspections/PyCompatibilityInspection/underscoresInNumericLiterals.py +++ b/python/testData/inspections/PyCompatibilityInspection/underscoresInNumericLiterals.py @@ -3,7 +3,7 @@ # oct 0o1_23 -01_23 +01_23 # bin 0b_0011_1111_0100_1110 diff --git a/python/testData/inspections/PyCompatibilityInspection/warningAboutAsyncAndAwaitInPy36.py b/python/testData/inspections/PyCompatibilityInspection/warningAboutAsyncAndAwaitInPy36.py index 391203a323a5..02d6773ed2a6 100644 --- a/python/testData/inspections/PyCompatibilityInspection/warningAboutAsyncAndAwaitInPy36.py +++ b/python/testData/inspections/PyCompatibilityInspection/warningAboutAsyncAndAwaitInPy36.py @@ -1,14 +1,14 @@ -class async(object): +class async(object): pass -class await(object): +class await(object): pass -def async(): +def async(): pass -def await(): +def await(): pass -async = 1 -await = 2 \ No newline at end of file +async = 1 +await = 2 \ No newline at end of file diff --git a/python/testData/inspections/PyCompatibilityInspection/yieldInsideAsyncDef.py b/python/testData/inspections/PyCompatibilityInspection/yieldInsideAsyncDef.py index 5856c3a938ef..3573a332b110 100644 --- a/python/testData/inspections/PyCompatibilityInspection/yieldInsideAsyncDef.py +++ b/python/testData/inspections/PyCompatibilityInspection/yieldInsideAsyncDef.py @@ -1,5 +1,5 @@ -async def foo(x): - await x +async def foo(x): + await x yield x - yield from x + yield from x return x diff --git a/python/testData/inspections/PyUnusedLocalInspection/tupleUnpacking.py b/python/testData/inspections/PyUnusedLocalInspection/tupleUnpacking.py index 1e504dff73bb..e18eec33ab41 100644 --- a/python/testData/inspections/PyUnusedLocalInspection/tupleUnpacking.py +++ b/python/testData/inspections/PyUnusedLocalInspection/tupleUnpacking.py @@ -3,8 +3,8 @@ def foo(): print x def test_vlu(): - *h, t = [1, 2, 3] # fail + *h, t = [1, 2, 3] # fail def test_vlu(): - *h, t = [1, 2, 3] # pass + *h, t = [1, 2, 3] # pass print(t) \ No newline at end of file diff --git a/python/testData/inspections/ReplacePrint.py b/python/testData/inspections/ReplacePrint.py index e3be5fa073e4..255535f84431 100644 --- a/python/testData/inspections/ReplacePrint.py +++ b/python/testData/inspections/ReplacePrint.py @@ -1 +1 @@ -print "foo" \ No newline at end of file +print "foo" \ No newline at end of file diff --git a/python/testData/quickFixes/PyRemoveArgumentQuickFixTest/duplicateArg.py b/python/testData/quickFixes/PyRemoveArgumentQuickFixTest/duplicateArg.py index c3b927d94cfb..640d3b132a5e 100644 --- a/python/testData/quickFixes/PyRemoveArgumentQuickFixTest/duplicateArg.py +++ b/python/testData/quickFixes/PyRemoveArgumentQuickFixTest/duplicateArg.py @@ -3,6 +3,6 @@ def foo(*args): a = () b = () -foo(*a, *b) +foo(*a, *b) diff --git a/python/testData/quickFixes/PyRemoveArgumentQuickFixTest/duplicateKWArg.py b/python/testData/quickFixes/PyRemoveArgumentQuickFixTest/duplicateKWArg.py index 88646f80000e..8ef93174abc8 100644 --- a/python/testData/quickFixes/PyRemoveArgumentQuickFixTest/duplicateKWArg.py +++ b/python/testData/quickFixes/PyRemoveArgumentQuickFixTest/duplicateKWArg.py @@ -4,6 +4,6 @@ def foo(**args): a = {} b = {} -foo(**a, **b) +foo(**a, **b) diff --git a/python/testData/quickFixes/PyRemoveArgumentQuickFixTest/postKwArg.py b/python/testData/quickFixes/PyRemoveArgumentQuickFixTest/postKwArg.py index ccdde9bc9222..a8a6b2bc10ff 100644 --- a/python/testData/quickFixes/PyRemoveArgumentQuickFixTest/postKwArg.py +++ b/python/testData/quickFixes/PyRemoveArgumentQuickFixTest/postKwArg.py @@ -2,6 +2,6 @@ def foo(a, **args): pass b = {} -foo(**b, a=1) +foo(**b, a=1) diff --git a/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAsyncClassInPy36.py b/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAsyncClassInPy36.py index 2b9e795332ee..1bc666f3c3ba 100644 --- a/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAsyncClassInPy36.py +++ b/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAsyncClassInPy36.py @@ -1,2 +1,2 @@ -class async(object): +class async(object): pass \ No newline at end of file diff --git a/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAsyncFunctionInPy36.py b/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAsyncFunctionInPy36.py index eb240bca6b7c..918761ccb543 100644 --- a/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAsyncFunctionInPy36.py +++ b/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAsyncFunctionInPy36.py @@ -1,2 +1,2 @@ -def async(): +def async(): pass \ No newline at end of file diff --git a/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAsyncVariableInPy36.py b/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAsyncVariableInPy36.py index 213b45c5b1c6..cac5b9d8995d 100644 --- a/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAsyncVariableInPy36.py +++ b/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAsyncVariableInPy36.py @@ -1 +1 @@ -async = 1 \ No newline at end of file +async = 1 \ No newline at end of file diff --git a/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAwaitClassInPy36.py b/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAwaitClassInPy36.py index 08200f70fd1d..bcad16f68022 100644 --- a/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAwaitClassInPy36.py +++ b/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAwaitClassInPy36.py @@ -1,2 +1,2 @@ -class await(object): +class await(object): pass \ No newline at end of file diff --git a/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAwaitFunctionInPy36.py b/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAwaitFunctionInPy36.py index 4dbf8430e8d5..308f572d59a7 100644 --- a/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAwaitFunctionInPy36.py +++ b/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAwaitFunctionInPy36.py @@ -1,2 +1,2 @@ -def await(): +def await(): pass \ No newline at end of file diff --git a/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAwaitVariableInPy36.py b/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAwaitVariableInPy36.py index c037073f701a..c992220190fd 100644 --- a/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAwaitVariableInPy36.py +++ b/python/testData/quickFixes/PyRenameElementQuickFixTest/renameAwaitVariableInPy36.py @@ -1 +1 @@ -await = 1 \ No newline at end of file +await = 1 \ No newline at end of file