mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
PY-53105 PEP 646: Render unpacked tuples as *tuple[T1, T2, ...], not as *(T1, T2, ...)
I prefer the notations used for defining a type and rendering it in the IDE not to diverge, unless there is a strong incentive to do that. Doing that for Callables is already forcing us to use two different type renderers for Quick Documentation and generating type hints. GitOrigin-RevId: f6340182bad60d6a7e94156aadc0f17440ee59d5
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ffda93c6fb
commit
b0b7d9aacd
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.jetbrains.python.psi.types;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
@@ -103,20 +104,12 @@ public final class PyGenericVariadicType implements PyTypeParameterType {
|
||||
@NotNull
|
||||
public String getElementTypesToStr() {
|
||||
if (myElementTypes == null) return "";
|
||||
StringBuilder res = new StringBuilder();
|
||||
res.append("(");
|
||||
for (int i = 0; i < myElementTypes.size(); ++i) {
|
||||
var type = myElementTypes.get(i);
|
||||
var name = type != null ? type.getName() : "Any";
|
||||
res.append(name);
|
||||
if (i < myElementTypes.size() - 1) {
|
||||
res.append(",");
|
||||
}
|
||||
}
|
||||
StringBuilder res = new StringBuilder("tuple[");
|
||||
StringUtil.join(myElementTypes, type -> type != null ? type.getName() : "Any", ", ", res);
|
||||
if (isHomogeneous()) {
|
||||
res.append(", ...");
|
||||
}
|
||||
res.append(")");
|
||||
res.append("]");
|
||||
return res.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public final class PyTypeParameterMappingTest extends PyTestCase {
|
||||
|
||||
public void testMatchingTypeVarTupleAtTheBeginning() {
|
||||
doTestShapeMapping("*Ts, T", "int, T2, str", """
|
||||
*Ts -> *(int,T2)
|
||||
*Ts -> *tuple[int, T2]
|
||||
T -> str
|
||||
""");
|
||||
}
|
||||
@@ -48,14 +48,14 @@ public final class PyTypeParameterMappingTest extends PyTestCase {
|
||||
public void testMatchingTypeVarTupleAtTheEnd() {
|
||||
doTestShapeMapping("T, *Ts", "int, T2, str", """
|
||||
T -> int
|
||||
*Ts -> *(T2,str)
|
||||
*Ts -> *tuple[T2, str]
|
||||
""");
|
||||
}
|
||||
|
||||
public void testMatchingTypeVarTupleInTheMiddle() {
|
||||
doTestShapeMapping("T, *Ts, int", "int, T2, str, int", """
|
||||
T -> int
|
||||
*Ts -> *(T2,str)
|
||||
*Ts -> *tuple[T2, str]
|
||||
int -> int
|
||||
""");
|
||||
}
|
||||
@@ -129,7 +129,7 @@ public final class PyTypeParameterMappingTest extends PyTestCase {
|
||||
public void testExpectedTypeVarTupleMappedToUnpackedTuple() {
|
||||
doTestShapeMapping("T1, *Ts, T2", "int, *tuple[bool, ...], str", """
|
||||
T1 -> int
|
||||
*Ts -> *(bool, ...)
|
||||
*Ts -> *tuple[bool, ...]
|
||||
T2 -> str
|
||||
""");
|
||||
}
|
||||
@@ -137,7 +137,7 @@ public final class PyTypeParameterMappingTest extends PyTestCase {
|
||||
public void testExpectedTypeVarTupleMappedToSingleRemainingType() {
|
||||
doTestShapeMapping("T1, *Ts, T2", "int, bool, str", """
|
||||
T1 -> int
|
||||
*Ts -> *(bool)
|
||||
*Ts -> *tuple[bool]
|
||||
T2 -> str
|
||||
""");
|
||||
}
|
||||
@@ -145,7 +145,7 @@ public final class PyTypeParameterMappingTest extends PyTestCase {
|
||||
public void testExpectedTypeVarTupleMappedToEmptyUnpackedTuple() {
|
||||
doTestShapeMapping("T1, *Ts, T2", "int, str", """
|
||||
T1 -> int
|
||||
*Ts -> *()
|
||||
*Ts -> *tuple[]
|
||||
T2 -> str
|
||||
""");
|
||||
}
|
||||
@@ -153,7 +153,7 @@ public final class PyTypeParameterMappingTest extends PyTestCase {
|
||||
public void testExpectedUnboundUnpackedTupleMappedToEmptyUnpackedTuple() {
|
||||
doTestShapeMapping("T1, *tuple[bool, ...], T2", "int, str", """
|
||||
T1 -> int
|
||||
*(bool, ...) -> *()
|
||||
*tuple[bool, ...] -> *tuple[]
|
||||
T2 -> str
|
||||
""");
|
||||
}
|
||||
@@ -176,7 +176,7 @@ public final class PyTypeParameterMappingTest extends PyTestCase {
|
||||
public void testExtractingElementsFromUnboundTupleTypeFollowedByExpectedVariadic() {
|
||||
doTestShapeMapping("T, *Ts", "*tuple[float, ...]", """
|
||||
T -> float
|
||||
*Ts -> *(float, ...)
|
||||
*Ts -> *tuple[float, ...]
|
||||
""");
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ public final class PyTypeParameterMappingTest extends PyTestCase {
|
||||
doTestShapeMapping("int, T, *Ts, T1", "int, *tuple[float, ...], int, str", """
|
||||
int -> int
|
||||
T -> float
|
||||
*Ts -> *(*(float, ...),int)
|
||||
*Ts -> *tuple[*tuple[float, ...], int]
|
||||
T1 -> str
|
||||
""");
|
||||
}
|
||||
@@ -251,7 +251,7 @@ public final class PyTypeParameterMappingTest extends PyTestCase {
|
||||
public void testMappingVariadicTypeToOnePositionalParameter() {
|
||||
doTestParameterListMapping("int, *Ts, str", "x: int, y: str, z: bool", """
|
||||
int -> int
|
||||
*Ts -> *(str)
|
||||
*Ts -> *tuple[str]
|
||||
str -> bool
|
||||
""");
|
||||
}
|
||||
@@ -259,7 +259,7 @@ public final class PyTypeParameterMappingTest extends PyTestCase {
|
||||
public void testMappingVariadicTypeToNoPositionalParameters() {
|
||||
doTestParameterListMapping("int, *Ts, str", "x: int, z: bool", """
|
||||
int -> int
|
||||
*Ts -> *()
|
||||
*Ts -> *tuple[]
|
||||
str -> bool
|
||||
""");
|
||||
}
|
||||
@@ -267,7 +267,7 @@ public final class PyTypeParameterMappingTest extends PyTestCase {
|
||||
public void testMappingVariadicTypeToFewPositionalParameters() {
|
||||
doTestParameterListMapping("int, *Ts", "x: int, y: str, z: bool", """
|
||||
int -> int
|
||||
*Ts -> *(str,bool)
|
||||
*Ts -> *tuple[str, bool]
|
||||
""");
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ public final class PyTypeParameterMappingTest extends PyTestCase {
|
||||
public void testMappingVariadicTypeToPositionalVarargParameter() {
|
||||
doTestParameterListMapping("int, *Ts", "x: int, y: str = 'a', *args: bool, z: int = 42", """
|
||||
int -> int
|
||||
*Ts -> *(str,*(bool, ...))
|
||||
*Ts -> *tuple[str, *tuple[bool, ...]]
|
||||
""");
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ public final class PyTypeParameterMappingTest extends PyTestCase {
|
||||
public void testVariadicTypesToFixedSizePositionalVarargPrecededWithDefaults() {
|
||||
doTestParameterListMapping("int, *Ts, bool", "x: int, y: str = 'a', *args: *tuple[str, bool]", """
|
||||
int -> int
|
||||
*Ts -> *(str,str)
|
||||
*Ts -> *tuple[str, str]
|
||||
bool -> bool
|
||||
""");
|
||||
}
|
||||
|
||||
@@ -2573,7 +2573,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-53105
|
||||
public void testVariadicGenericMatchWithHomogeneousGenericVariadicAndOtherTypes() {
|
||||
doTest("Array[*(Any, ...), int, str]","""
|
||||
doTest("Array[*tuple[Any, ...], int, str]","""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TypeVarTuple
|
||||
@@ -2596,7 +2596,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-53105
|
||||
public void testVariadicGenericMatchWithHomogeneousGenericVariadicAndOtherTypesPrefixSuffix() {
|
||||
doTest("Array[*(Any, ...), int, float, str]","""
|
||||
doTest("Array[*tuple[Any, ...], int, float, str]","""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TypeVarTuple
|
||||
@@ -2622,7 +2622,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-53105
|
||||
public void testVariadicGenericMatchWithHomogeneousGenericVariadicAmbiguousMatchActualGenericFirst() {
|
||||
doTest("Array[*(float, ...), int, float, str]", """
|
||||
doTest("Array[*tuple[float, ...], int, float, str]", """
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TypeVarTuple
|
||||
@@ -2648,7 +2648,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-53105
|
||||
public void testGenericVariadicsNotUnifiedBothAmbiguousMatch() {
|
||||
doTest("Array[*(int, ...), int, int, str]", """
|
||||
doTest("Array[*tuple[int, ...], int, int, str]", """
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TypeVarTuple
|
||||
@@ -2674,7 +2674,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-53105
|
||||
public void testGenericVariadicsNotUnifiedBothActualHomogeneousGenericFirst() {
|
||||
doTest("Array[float, *(float, ...)]","""
|
||||
doTest("Array[float, *tuple[float, ...]]","""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TypeVarTuple
|
||||
@@ -2699,7 +2699,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-53105
|
||||
public void testGenericVariadicsNotUnifiedBothActualHomogeneousGenericLast() {
|
||||
doTest("Array[*(float, ...), float]","""
|
||||
doTest("Array[*tuple[float, ...], float]","""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TypeVarTuple
|
||||
@@ -2724,7 +2724,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-53105
|
||||
public void testGenericVariadicsNotUnifiedBothActualHomogeneousGenericsBothSides() {
|
||||
doTest("Array[float, *(float, ...), float, float]","""
|
||||
doTest("Array[float, *tuple[float, ...], float, float]","""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TypeVarTuple
|
||||
|
||||
@@ -1341,55 +1341,57 @@ public class Py3TypeCheckerInspectionTest extends PyInspectionTestCase {
|
||||
|
||||
// PY-53105
|
||||
public void testVariadicGenericUnboundTupleInFunction() {
|
||||
doTestByText("from typing import Generic, TypeVarTuple, Tuple, Any\n" +
|
||||
"\n" +
|
||||
"Ts = TypeVarTuple('Ts')\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"class Array(Generic[*Ts]):\n" +
|
||||
" def __init__(self, shape: Tuple[*Ts]):\n" +
|
||||
" ...\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"def foo(x: Array[int, *Tuple[Any, ...], str]) -> None:\n" +
|
||||
" ...\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"x: Array[int, list[str], bool, str]\n" +
|
||||
"foo(x)\n" +
|
||||
"\n" +
|
||||
"y: Array[int, str]\n" +
|
||||
"foo(y)\n" +
|
||||
"\n" +
|
||||
"z: Array[int]\n" +
|
||||
"foo(<warning descr=\"Expected type 'Array[int, *(Any, ...), str]', got 'Array[int]' instead\">z</warning>)\n" +
|
||||
"\n" +
|
||||
"t: Array[str]\n" +
|
||||
"foo(<warning descr=\"Expected type 'Array[int, *(Any, ...), str]', got 'Array[str]' instead\">t</warning>)\n" +
|
||||
"\n" +
|
||||
"k: Array[int, int]\n" +
|
||||
"foo(<warning descr=\"Expected type 'Array[int, *(Any, ...), str]', got 'Array[int, int]' instead\">k</warning>)\n");
|
||||
doTestByText("""
|
||||
from typing import Generic, TypeVarTuple, Tuple, Any
|
||||
|
||||
Ts = TypeVarTuple('Ts')
|
||||
|
||||
|
||||
class Array(Generic[*Ts]):
|
||||
def __init__(self, shape: Tuple[*Ts]):
|
||||
...
|
||||
|
||||
|
||||
def foo(x: Array[int, *Tuple[Any, ...], str]) -> None:
|
||||
...
|
||||
|
||||
|
||||
x: Array[int, list[str], bool, str]
|
||||
foo(x)
|
||||
|
||||
y: Array[int, str]
|
||||
foo(y)
|
||||
|
||||
z: Array[int]
|
||||
foo(<warning descr="Expected type 'Array[int, *tuple[Any, ...], str]', got 'Array[int]' instead">z</warning>)
|
||||
|
||||
t: Array[str]
|
||||
foo(<warning descr="Expected type 'Array[int, *tuple[Any, ...], str]', got 'Array[str]' instead">t</warning>)
|
||||
|
||||
k: Array[int, int]
|
||||
foo(<warning descr="Expected type 'Array[int, *tuple[Any, ...], str]', got 'Array[int, int]' instead">k</warning>)
|
||||
""");
|
||||
}
|
||||
|
||||
// PY-53105
|
||||
public void testVariadicGenericStarArgsNamedParameters() {
|
||||
doTestByText("""
|
||||
from typing import Tuple, TypeVarTuple
|
||||
|
||||
|
||||
Ts = TypeVarTuple('Ts')
|
||||
|
||||
|
||||
|
||||
|
||||
def foo(a: str, *args: *Tuple[*Ts, int], b: str, c: bool) -> None: ...
|
||||
|
||||
|
||||
|
||||
|
||||
foo('', 1, True, [1], 42, b='', c=True)
|
||||
foo('', 42, b='', c=True)
|
||||
foo('', True, 42, c=True, b='')
|
||||
|
||||
foo('', b='', c=True<warning descr="Parameter 'args' unfilled, expected '*(*Ts,int)'">)</warning>
|
||||
foo('', <warning descr="Expected type '*(int)' (matched generic type '*(*Ts,int)'), got '*(LiteralString)' instead">''</warning>, b='', c=True)
|
||||
foo('', <warning descr="Expected type '*(LiteralString,int)' (matched generic type '*(*Ts,int)'), got '*(LiteralString,list)' instead">''</warning>, <warning descr="Expected type '*(LiteralString,int)' (matched generic type '*(*Ts,int)'), got '*(LiteralString,list)' instead">[False]</warning>, b='', c=True)
|
||||
foo('', <warning descr="Expected type '*(LiteralString,LiteralString,LiteralString,int)' (matched generic type '*(*Ts,int)'), got '*(LiteralString,LiteralString,LiteralString,float)' instead">''</warning>, <warning descr="Expected type '*(LiteralString,LiteralString,LiteralString,int)' (matched generic type '*(*Ts,int)'), got '*(LiteralString,LiteralString,LiteralString,float)' instead">''</warning>, <warning descr="Expected type '*(LiteralString,LiteralString,LiteralString,int)' (matched generic type '*(*Ts,int)'), got '*(LiteralString,LiteralString,LiteralString,float)' instead">''</warning>, <warning descr="Expected type '*(LiteralString,LiteralString,LiteralString,int)' (matched generic type '*(*Ts,int)'), got '*(LiteralString,LiteralString,LiteralString,float)' instead">1.1</warning>, b='', c=True)
|
||||
|
||||
foo('', b='', c=True<warning descr="Parameter 'args' unfilled, expected '*tuple[*Ts, int]'">)</warning>
|
||||
foo('', <warning descr="Expected type '*tuple[int]' (matched generic type '*tuple[*Ts, int]'), got '*tuple[LiteralString]' instead">''</warning>, b='', c=True)
|
||||
foo('', <warning descr="Expected type '*tuple[LiteralString, int]' (matched generic type '*tuple[*Ts, int]'), got '*tuple[LiteralString, list]' instead">''</warning>, <warning descr="Expected type '*tuple[LiteralString, int]' (matched generic type '*tuple[*Ts, int]'), got '*tuple[LiteralString, list]' instead">[False]</warning>, b='', c=True)
|
||||
foo('', <warning descr="Expected type '*tuple[LiteralString, LiteralString, LiteralString, int]' (matched generic type '*tuple[*Ts, int]'), got '*tuple[LiteralString, LiteralString, LiteralString, float]' instead">''</warning>, <warning descr="Expected type '*tuple[LiteralString, LiteralString, LiteralString, int]' (matched generic type '*tuple[*Ts, int]'), got '*tuple[LiteralString, LiteralString, LiteralString, float]' instead">''</warning>, <warning descr="Expected type '*tuple[LiteralString, LiteralString, LiteralString, int]' (matched generic type '*tuple[*Ts, int]'), got '*tuple[LiteralString, LiteralString, LiteralString, float]' instead">''</warning>, <warning descr="Expected type '*tuple[LiteralString, LiteralString, LiteralString, int]' (matched generic type '*tuple[*Ts, int]'), got '*tuple[LiteralString, LiteralString, LiteralString, float]' instead">1.1</warning>, b='', c=True)
|
||||
""");
|
||||
}
|
||||
|
||||
@@ -1397,26 +1399,26 @@ public class Py3TypeCheckerInspectionTest extends PyInspectionTestCase {
|
||||
public void testVariadicGenericStarArgsTupleAndUnpackedTuple() {
|
||||
doTestByText("""
|
||||
from typing import Tuple, TypeVarTuple
|
||||
|
||||
|
||||
Ts = TypeVarTuple('Ts')
|
||||
|
||||
|
||||
|
||||
|
||||
def foo(a: Tuple[*Ts], *args: *Tuple[str, *Ts, int], b: str) -> None: ...
|
||||
|
||||
|
||||
|
||||
|
||||
foo(('', 1), '', '', 1, 1, b='')
|
||||
foo((1,1), '', 1, 1, 1, b='')
|
||||
foo(('',), '', '', 1, b='')
|
||||
foo((), '', 1, b='')
|
||||
foo(([], {}), '', [], {}, 1, b='')
|
||||
|
||||
foo(('', 1), b=''<warning descr="Parameter 'args' unfilled, expected '*(str,LiteralString,int,int)'">)</warning>
|
||||
foo(('', 1), <warning descr="Expected type '*(str,LiteralString,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,LiteralString,LiteralString,int)' instead">''</warning>, <warning descr="Expected type '*(str,LiteralString,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,LiteralString,LiteralString,int)' instead">''</warning>, <warning descr="Expected type '*(str,LiteralString,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,LiteralString,LiteralString,int)' instead">''</warning>, <warning descr="Expected type '*(str,LiteralString,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,LiteralString,LiteralString,int)' instead">1</warning>, b='')
|
||||
foo((1,1), <warning descr="Expected type '*(str,int,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,int)' instead">''</warning>, <warning descr="Expected type '*(str,int,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,int)' instead">1</warning>, <warning descr="Expected type '*(str,int,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,int)' instead">1</warning>, b='')
|
||||
foo(('',), <warning descr="Expected type '*(str,LiteralString,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,int)' instead">''</warning>, <warning descr="Expected type '*(str,LiteralString,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,int)' instead">1</warning>, <warning descr="Expected type '*(str,LiteralString,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,int)' instead">1</warning>, b='')
|
||||
|
||||
foo(('', 1), b=''<warning descr="Parameter 'args' unfilled, expected '*tuple[str, LiteralString, int, int]'">)</warning>
|
||||
foo(('', 1), <warning descr="Expected type '*tuple[str, LiteralString, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, LiteralString, LiteralString, int]' instead">''</warning>, <warning descr="Expected type '*tuple[str, LiteralString, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, LiteralString, LiteralString, int]' instead">''</warning>, <warning descr="Expected type '*tuple[str, LiteralString, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, LiteralString, LiteralString, int]' instead">''</warning>, <warning descr="Expected type '*tuple[str, LiteralString, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, LiteralString, LiteralString, int]' instead">1</warning>, b='')
|
||||
foo((1,1), <warning descr="Expected type '*tuple[str, int, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, int]' instead">''</warning>, <warning descr="Expected type '*tuple[str, int, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, int]' instead">1</warning>, <warning descr="Expected type '*tuple[str, int, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, int]' instead">1</warning>, b='')
|
||||
foo(('',), <warning descr="Expected type '*tuple[str, LiteralString, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, int]' instead">''</warning>, <warning descr="Expected type '*tuple[str, LiteralString, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, int]' instead">1</warning>, <warning descr="Expected type '*tuple[str, LiteralString, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, int]' instead">1</warning>, b='')
|
||||
x: Any
|
||||
foo((), <warning descr="Expected type '*(str,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,Any)' instead">''</warning>, <warning descr="Expected type '*(str,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,Any)' instead">42</warning>, <warning descr="Expected type '*(str,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,Any)' instead">x</warning>, b='')
|
||||
foo(([], {}), <warning descr="Expected type '*(str,list,TypedDict,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,list,TypedDict)' instead">''</warning>, <warning descr="Expected type '*(str,list,TypedDict,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,list,TypedDict)' instead">[]</warning>, <warning descr="Expected type '*(str,list,TypedDict,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,list,TypedDict)' instead">{}</warning>, b='')
|
||||
foo((), <warning descr="Expected type '*tuple[str, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, Any]' instead">''</warning>, <warning descr="Expected type '*tuple[str, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, Any]' instead">42</warning>, <warning descr="Expected type '*tuple[str, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, Any]' instead">x</warning>, b='')
|
||||
foo(([], {}), <warning descr="Expected type '*tuple[str, list, TypedDict, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, list, TypedDict]' instead">''</warning>, <warning descr="Expected type '*tuple[str, list, TypedDict, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, list, TypedDict]' instead">[]</warning>, <warning descr="Expected type '*tuple[str, list, TypedDict, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, list, TypedDict]' instead">{}</warning>, b='')
|
||||
""");
|
||||
}
|
||||
|
||||
@@ -1442,26 +1444,26 @@ public class Py3TypeCheckerInspectionTest extends PyInspectionTestCase {
|
||||
public void testVariadicGenericStarArgsOfVariadicGenericPrefixSuffix() {
|
||||
doTestByText("""
|
||||
from typing import Tuple, TypeVarTuple
|
||||
|
||||
|
||||
Ts = TypeVarTuple('Ts')
|
||||
|
||||
|
||||
|
||||
|
||||
def foo(a: Tuple[*Ts], *args: *Tuple[str, *Ts, int], b: str) -> None: ...
|
||||
|
||||
|
||||
|
||||
|
||||
foo(('', 1), '', '', 1, 1, b='')
|
||||
foo((1,1), '', 1, 1, 1, b='')
|
||||
foo(('',), '', '', 1, b='')
|
||||
foo((), '', 1, b='')
|
||||
foo(([], {}), '', [], {}, 1, b='')
|
||||
|
||||
foo(('', 1), b=''<warning descr="Parameter 'args' unfilled, expected '*(str,LiteralString,int,int)'">)</warning>
|
||||
foo(('', 1), <warning descr="Expected type '*(str,LiteralString,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,LiteralString,LiteralString,int)' instead">''</warning>, <warning descr="Expected type '*(str,LiteralString,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,LiteralString,LiteralString,int)' instead">''</warning>, <warning descr="Expected type '*(str,LiteralString,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,LiteralString,LiteralString,int)' instead">''</warning>, <warning descr="Expected type '*(str,LiteralString,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,LiteralString,LiteralString,int)' instead">1</warning>, b='')
|
||||
foo((1,1), <warning descr="Expected type '*(str,int,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,int)' instead">''</warning>, <warning descr="Expected type '*(str,int,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,int)' instead">1</warning>, <warning descr="Expected type '*(str,int,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,int)' instead">1</warning>, b='')
|
||||
foo(('',), <warning descr="Expected type '*(str,LiteralString,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,int)' instead">''</warning>, <warning descr="Expected type '*(str,LiteralString,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,int)' instead">1</warning>, <warning descr="Expected type '*(str,LiteralString,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,int)' instead">1</warning>, b='')
|
||||
|
||||
foo(('', 1), b=''<warning descr="Parameter 'args' unfilled, expected '*tuple[str, LiteralString, int, int]'">)</warning>
|
||||
foo(('', 1), <warning descr="Expected type '*tuple[str, LiteralString, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, LiteralString, LiteralString, int]' instead">''</warning>, <warning descr="Expected type '*tuple[str, LiteralString, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, LiteralString, LiteralString, int]' instead">''</warning>, <warning descr="Expected type '*tuple[str, LiteralString, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, LiteralString, LiteralString, int]' instead">''</warning>, <warning descr="Expected type '*tuple[str, LiteralString, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, LiteralString, LiteralString, int]' instead">1</warning>, b='')
|
||||
foo((1,1), <warning descr="Expected type '*tuple[str, int, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, int]' instead">''</warning>, <warning descr="Expected type '*tuple[str, int, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, int]' instead">1</warning>, <warning descr="Expected type '*tuple[str, int, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, int]' instead">1</warning>, b='')
|
||||
foo(('',), <warning descr="Expected type '*tuple[str, LiteralString, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, int]' instead">''</warning>, <warning descr="Expected type '*tuple[str, LiteralString, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, int]' instead">1</warning>, <warning descr="Expected type '*tuple[str, LiteralString, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, int]' instead">1</warning>, b='')
|
||||
x: Any
|
||||
foo((), <warning descr="Expected type '*(str,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,Any)' instead">''</warning>, <warning descr="Expected type '*(str,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,Any)' instead">42</warning>, <warning descr="Expected type '*(str,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,Any)' instead">x</warning>, b='')
|
||||
foo(([], {}), <warning descr="Expected type '*(str,list,TypedDict,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,list,TypedDict)' instead">''</warning>, <warning descr="Expected type '*(str,list,TypedDict,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,list,TypedDict)' instead">[]</warning>, <warning descr="Expected type '*(str,list,TypedDict,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,list,TypedDict)' instead">{}</warning>, b='')
|
||||
foo((), <warning descr="Expected type '*tuple[str, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, Any]' instead">''</warning>, <warning descr="Expected type '*tuple[str, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, Any]' instead">42</warning>, <warning descr="Expected type '*tuple[str, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, Any]' instead">x</warning>, b='')
|
||||
foo(([], {}), <warning descr="Expected type '*tuple[str, list, TypedDict, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, list, TypedDict]' instead">''</warning>, <warning descr="Expected type '*tuple[str, list, TypedDict, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, list, TypedDict]' instead">[]</warning>, <warning descr="Expected type '*tuple[str, list, TypedDict, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, list, TypedDict]' instead">{}</warning>, b='')
|
||||
""");
|
||||
}
|
||||
|
||||
@@ -1469,26 +1471,26 @@ public class Py3TypeCheckerInspectionTest extends PyInspectionTestCase {
|
||||
public void testVariadicGenericStarArgsPrefixSuffix() {
|
||||
doTestByText("""
|
||||
from typing import Tuple, TypeVarTuple
|
||||
|
||||
|
||||
Ts = TypeVarTuple('Ts')
|
||||
|
||||
|
||||
|
||||
|
||||
def foo(a: Tuple[*Ts], *args: *Tuple[str, *Ts, int], b: str) -> None: ...
|
||||
|
||||
|
||||
|
||||
|
||||
foo(('', 1), '', '', 1, 1, b='')
|
||||
foo((1,1), '', 1, 1, 1, b='')
|
||||
foo(('',), '', '', 1, b='')
|
||||
foo((), '', 1, b='')
|
||||
foo(([], {}), '', [], {}, 1, b='')
|
||||
|
||||
foo(('', 1), b=''<warning descr="Parameter 'args' unfilled, expected '*(str,LiteralString,int,int)'">)</warning>
|
||||
foo(('', 1), <warning descr="Expected type '*(str,LiteralString,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,LiteralString,LiteralString,int)' instead">''</warning>, <warning descr="Expected type '*(str,LiteralString,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,LiteralString,LiteralString,int)' instead">''</warning>, <warning descr="Expected type '*(str,LiteralString,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,LiteralString,LiteralString,int)' instead">''</warning>, <warning descr="Expected type '*(str,LiteralString,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,LiteralString,LiteralString,int)' instead">1</warning>, b='')
|
||||
foo((1,1), <warning descr="Expected type '*(str,int,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,int)' instead">''</warning>, <warning descr="Expected type '*(str,int,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,int)' instead">1</warning>, <warning descr="Expected type '*(str,int,int,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,int)' instead">1</warning>, b='')
|
||||
foo(('',), <warning descr="Expected type '*(str,LiteralString,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,int)' instead">''</warning>, <warning descr="Expected type '*(str,LiteralString,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,int)' instead">1</warning>, <warning descr="Expected type '*(str,LiteralString,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,int)' instead">1</warning>, b='')
|
||||
|
||||
foo(('', 1), b=''<warning descr="Parameter 'args' unfilled, expected '*tuple[str, LiteralString, int, int]'">)</warning>
|
||||
foo(('', 1), <warning descr="Expected type '*tuple[str, LiteralString, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, LiteralString, LiteralString, int]' instead">''</warning>, <warning descr="Expected type '*tuple[str, LiteralString, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, LiteralString, LiteralString, int]' instead">''</warning>, <warning descr="Expected type '*tuple[str, LiteralString, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, LiteralString, LiteralString, int]' instead">''</warning>, <warning descr="Expected type '*tuple[str, LiteralString, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, LiteralString, LiteralString, int]' instead">1</warning>, b='')
|
||||
foo((1,1), <warning descr="Expected type '*tuple[str, int, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, int]' instead">''</warning>, <warning descr="Expected type '*tuple[str, int, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, int]' instead">1</warning>, <warning descr="Expected type '*tuple[str, int, int, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, int]' instead">1</warning>, b='')
|
||||
foo(('',), <warning descr="Expected type '*tuple[str, LiteralString, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, int]' instead">''</warning>, <warning descr="Expected type '*tuple[str, LiteralString, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, int]' instead">1</warning>, <warning descr="Expected type '*tuple[str, LiteralString, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, int]' instead">1</warning>, b='')
|
||||
x: Any
|
||||
foo((), <warning descr="Expected type '*(str,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,Any)' instead">''</warning>, <warning descr="Expected type '*(str,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,Any)' instead">42</warning>, <warning descr="Expected type '*(str,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,int,Any)' instead">x</warning>, b='')
|
||||
foo(([], {}), <warning descr="Expected type '*(str,list,TypedDict,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,list,TypedDict)' instead">''</warning>, <warning descr="Expected type '*(str,list,TypedDict,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,list,TypedDict)' instead">[]</warning>, <warning descr="Expected type '*(str,list,TypedDict,int)' (matched generic type '*(str,*Ts,int)'), got '*(LiteralString,list,TypedDict)' instead">{}</warning>, b='')
|
||||
foo((), <warning descr="Expected type '*tuple[str, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, Any]' instead">''</warning>, <warning descr="Expected type '*tuple[str, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, Any]' instead">42</warning>, <warning descr="Expected type '*tuple[str, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, int, Any]' instead">x</warning>, b='')
|
||||
foo(([], {}), <warning descr="Expected type '*tuple[str, list, TypedDict, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, list, TypedDict]' instead">''</warning>, <warning descr="Expected type '*tuple[str, list, TypedDict, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, list, TypedDict]' instead">[]</warning>, <warning descr="Expected type '*tuple[str, list, TypedDict, int]' (matched generic type '*tuple[str, *Ts, int]'), got '*tuple[LiteralString, list, TypedDict]' instead">{}</warning>, b='')
|
||||
""");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user