mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
[pycharm] PY-79331 render type as "type", not "Type"
IJ-MR-159663 GitOrigin-RevId: ef585e7409bc1d92f54d3fdac6beae8dca58cb1f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0c9449e71d
commit
d412ed3e87
@@ -391,8 +391,7 @@ public final class PyTypeHintGenerationUtil {
|
||||
}
|
||||
|
||||
private void addTypingTypeIfNeeded(@NotNull PyType type) {
|
||||
// TODO in Python 3.9+ use the builtin "type" instead of "typing.Type"
|
||||
if (type instanceof PyInstantiableType<?> instantiableType && instantiableType.isDefinition()) {
|
||||
if (useGenericAliasFromTyping && type instanceof PyInstantiableType<?> instantiableType && instantiableType.isDefinition()) {
|
||||
typingTypes.add("Type");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,9 +221,11 @@ public class PyTypeModelBuilder {
|
||||
|
||||
static class ClassObjectType extends TypeModel {
|
||||
private final TypeModel classType;
|
||||
private final boolean useTypingAlias;
|
||||
|
||||
ClassObjectType(TypeModel classType) {
|
||||
ClassObjectType(TypeModel classType, boolean useTypingAlias) {
|
||||
this.classType = classType;
|
||||
this.useTypingAlias = useTypingAlias;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -300,7 +302,11 @@ public class PyTypeModelBuilder {
|
||||
result = NamedType.nameOrAny(type);
|
||||
}
|
||||
else {
|
||||
result = new ClassObjectType(build(instanceType, allowUnions));
|
||||
boolean useTypingAlias = PythonLanguageLevelPusher
|
||||
.getLanguageLevelForFile(myContext.getOrigin().getOriginalFile())
|
||||
.isOlderThan(LanguageLevel.PYTHON39);
|
||||
|
||||
result = new ClassObjectType(build(instanceType, allowUnions), useTypingAlias);
|
||||
}
|
||||
}
|
||||
else if (type instanceof PyNamedTupleType) {
|
||||
@@ -357,7 +363,10 @@ public class PyTypeModelBuilder {
|
||||
}
|
||||
else if (ContainerUtil.all(unionMembers, t -> t instanceof PyClassType && ((PyClassType)t).isDefinition())) {
|
||||
final List<TypeModel> instanceTypes = ContainerUtil.map(unionMembers, t -> build(((PyClassType)t).toInstance(), allowUnions));
|
||||
result = new ClassObjectType(new OneOf(instanceTypes, PyTypingTypeProvider.isBitwiseOrUnionAvailable(myContext)));
|
||||
|
||||
final var useTypingAlias = LanguageLevel.forElement(myContext.getOrigin().getOriginalFile()).isOlderThan(LanguageLevel.PYTHON39);
|
||||
|
||||
result = new ClassObjectType(new OneOf(instanceTypes, PyTypingTypeProvider.isBitwiseOrUnionAvailable(myContext)), useTypingAlias);
|
||||
}
|
||||
else {
|
||||
result = new OneOf(Collections2.transform(unionMembers, t -> build(t, false)),
|
||||
@@ -798,7 +807,12 @@ public class PyTypeModelBuilder {
|
||||
|
||||
@Override
|
||||
public void classObject(ClassObjectType type) {
|
||||
add(escaped("Type")); //NON-NLS
|
||||
if (type.useTypingAlias) {
|
||||
add(escaped("Type")); //NON-NLS
|
||||
}
|
||||
else {
|
||||
add(styled("type", PyHighlighter.PY_BUILTIN_NAME)); //NON-NLS
|
||||
}
|
||||
add(styled("[", PyHighlighter.PY_BRACKETS));
|
||||
type.classType.accept(this);
|
||||
add(styled("]", PyHighlighter.PY_BRACKETS));
|
||||
|
||||
@@ -21,7 +21,7 @@ close(f)
|
||||
r = Resource()
|
||||
close(r)
|
||||
|
||||
# There must be a warning "Expected type 'SupportsClose', got 'Type[Resource]' instead".
|
||||
# There must be a warning "Expected type 'SupportsClose', got 'type[Resource]' instead".
|
||||
# To fix this in PyTypeChecker.match(PyCallableType, PyCallableType, MatchContext) should be added checking named, optional and star params, not only positional ones.
|
||||
# close(Resource)
|
||||
|
||||
|
||||
@@ -12,4 +12,4 @@ def foo(arg: P):
|
||||
pass
|
||||
|
||||
foo(C())
|
||||
foo(<warning descr="Expected type 'P', got 'Type[C]' instead">C</warning>)
|
||||
foo(<warning descr="Expected type 'P', got 'type[C]' instead">C</warning>)
|
||||
@@ -6,7 +6,7 @@ class MyClass:
|
||||
def expects_myclass(x: Type[MyClass]):
|
||||
pass
|
||||
|
||||
expects_myclass(<warning descr="Expected type 'Type[MyClass]', got 'MyClass' instead">MyClass()</warning>)
|
||||
expects_myclass(<warning descr="Expected type 'type[MyClass]', got 'MyClass' instead">MyClass()</warning>)
|
||||
expects_class(MyClass)
|
||||
|
||||
T1 = TypeVar('T1')
|
||||
@@ -14,23 +14,23 @@ def expects_any_class(x: Type[T1]):
|
||||
pass
|
||||
|
||||
expects_any_class(MyClass)
|
||||
expects_any_class(<warning descr="Expected type 'Type[T1]', got 'MyClass' instead">MyClass()</warning>)
|
||||
expects_any_class(<warning descr="Expected type 'type[T1]', got 'MyClass' instead">MyClass()</warning>)
|
||||
expects_any_class(object)
|
||||
expects_any_class(<warning descr="Expected type 'Type[T1]', got 'object' instead">object()</warning>)
|
||||
expects_any_class(<warning descr="Expected type 'type[T1]', got 'object' instead">object()</warning>)
|
||||
|
||||
T2 = TypeVar('T2', MyClass)
|
||||
def expects_myclass_descendant(x: Type[T2]):
|
||||
pass
|
||||
|
||||
expects_myclass_descendant(MyClass)
|
||||
expects_myclass_descendant(<warning descr="Expected type 'Type[T2 ≤: MyClass]', got 'MyClass' instead">MyClass()</warning>)
|
||||
expects_myclass_descendant(<warning descr="Expected type 'Type[T2 ≤: MyClass]', got 'Type[object]' instead">object</warning>)
|
||||
expects_myclass_descendant(<warning descr="Expected type 'Type[T2 ≤: MyClass]', got 'object' instead">object()</warning>)
|
||||
expects_myclass_descendant(<warning descr="Expected type 'type[T2 ≤: MyClass]', got 'MyClass' instead">MyClass()</warning>)
|
||||
expects_myclass_descendant(<warning descr="Expected type 'type[T2 ≤: MyClass]', got 'type[object]' instead">object</warning>)
|
||||
expects_myclass_descendant(<warning descr="Expected type 'type[T2 ≤: MyClass]', got 'object' instead">object()</warning>)
|
||||
|
||||
def expects_myclass_descendant_or_none(x: Optional[Type[T2]]):
|
||||
pass
|
||||
|
||||
expects_myclass_descendant_or_none(MyClass)
|
||||
expects_myclass_descendant_or_none(<warning descr="Expected type 'Type[T2 ≤: MyClass] | None', got 'MyClass' instead">MyClass()</warning>)
|
||||
expects_myclass_descendant_or_none(<warning descr="Expected type 'Type[T2 ≤: MyClass] | None', got 'Type[object]' instead">object</warning>)
|
||||
expects_myclass_descendant_or_none(<warning descr="Expected type 'Type[T2 ≤: MyClass] | None', got 'object' instead">object()</warning>)
|
||||
expects_myclass_descendant_or_none(<warning descr="Expected type 'type[T2 ≤: MyClass] | None', got 'MyClass' instead">MyClass()</warning>)
|
||||
expects_myclass_descendant_or_none(<warning descr="Expected type 'type[T2 ≤: MyClass] | None', got 'type[object]' instead">object</warning>)
|
||||
expects_myclass_descendant_or_none(<warning descr="Expected type 'type[T2 ≤: MyClass] | None', got 'object' instead">object()</warning>)
|
||||
@@ -8,8 +8,8 @@ def expects_myclass_or_str1(x: Type[Union[MyClass, str]]):
|
||||
|
||||
expects_myclass_or_str1(MyClass)
|
||||
expects_myclass_or_str1(str)
|
||||
expects_myclass_or_str1(<warning descr="Expected type 'Type[MyClass | str]', got 'Type[int]' instead">int</warning>)
|
||||
expects_myclass_or_str1(<warning descr="Expected type 'Type[MyClass | str]', got 'int' instead">42</warning>)
|
||||
expects_myclass_or_str1(<warning descr="Expected type 'type[MyClass | str]', got 'type[int]' instead">int</warning>)
|
||||
expects_myclass_or_str1(<warning descr="Expected type 'type[MyClass | str]', got 'int' instead">42</warning>)
|
||||
|
||||
|
||||
def expects_myclass_or_str2(x: Union[Type[MyClass], Type[str]]):
|
||||
@@ -17,5 +17,5 @@ def expects_myclass_or_str2(x: Union[Type[MyClass], Type[str]]):
|
||||
|
||||
expects_myclass_or_str2(MyClass)
|
||||
expects_myclass_or_str2(str)
|
||||
expects_myclass_or_str2(<warning descr="Expected type 'Type[MyClass | str]', got 'Type[int]' instead">int</warning>)
|
||||
expects_myclass_or_str2(<warning descr="Expected type 'Type[MyClass | str]', got 'int' instead">42</warning>)
|
||||
expects_myclass_or_str2(<warning descr="Expected type 'type[MyClass | str]', got 'type[int]' instead">int</warning>)
|
||||
expects_myclass_or_str2(<warning descr="Expected type 'type[MyClass | str]', got 'int' instead">42</warning>)
|
||||
|
||||
@@ -3,12 +3,12 @@ from typing import Type, TypeVar
|
||||
|
||||
def expects_typing_Type(x: Type[str]):
|
||||
expects_builtin_type(x)
|
||||
expects_builtin_type(<warning descr="Expected type 'Type[str]', got 'Type[int]' instead">int</warning>)
|
||||
expects_builtin_type(<warning descr="Expected type 'type[str]', got 'type[int]' instead">int</warning>)
|
||||
|
||||
|
||||
def expects_builtin_type(x: type[str]):
|
||||
expects_typing_Type(x)
|
||||
expects_typing_Type(<warning descr="Expected type 'Type[str]', got 'Type[int]' instead">int</warning>)
|
||||
expects_typing_Type(<warning descr="Expected type 'type[str]', got 'type[int]' instead">int</warning>)
|
||||
|
||||
|
||||
T = TypeVar('T', bound=str)
|
||||
@@ -16,9 +16,9 @@ T = TypeVar('T', bound=str)
|
||||
|
||||
def expects_generic_builtin_type(x: type[T]):
|
||||
expects_generic_typing_Type(x)
|
||||
expects_generic_typing_Type(<warning descr="Expected type 'Type[T ≤: str]', got 'Type[int]' instead">int</warning>)
|
||||
expects_generic_typing_Type(<warning descr="Expected type 'type[T ≤: str]', got 'type[int]' instead">int</warning>)
|
||||
|
||||
|
||||
def expects_generic_typing_Type(x: Type[T]):
|
||||
expects_generic_builtin_type(x)
|
||||
expects_generic_builtin_type(<warning descr="Expected type 'Type[T ≤: str]', got 'Type[int]' instead">int</warning>)
|
||||
expects_generic_builtin_type(<warning descr="Expected type 'type[T ≤: str]', got 'type[int]' instead">int</warning>)
|
||||
|
||||
@@ -37,9 +37,9 @@ expects_type(object)
|
||||
expects_typing_type(type)
|
||||
expects_typing_type_any(type)
|
||||
expects_typing_type(object)
|
||||
expects_str_class(<warning descr="Expected type 'Type[str]', got 'type' instead">type</warning>)
|
||||
expects_str_class(<warning descr="Expected type 'type[str]', got 'type' instead">type</warning>)
|
||||
expects_any_type_via_type_var(type)
|
||||
expects_str_subclass(<warning descr="Expected type 'Type[T ≤: str]', got 'type' instead">type</warning>)
|
||||
expects_str_subclass(<warning descr="Expected type 'type[T ≤: str]', got 'type' instead">type</warning>)
|
||||
expects_object(type)
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ def f2(p: B):
|
||||
return p
|
||||
|
||||
|
||||
f2(<warning descr="Expected type 'B ≤: str', got 'Type[str]' instead">str</warning>)
|
||||
f2(<warning descr="Expected type 'B ≤: str', got 'type[str]' instead">str</warning>)
|
||||
|
||||
|
||||
def g1(p):
|
||||
@@ -33,6 +33,6 @@ def g2(p):
|
||||
"""
|
||||
|
||||
|
||||
g2(<warning descr="Expected type 'T ≤: str', got 'Type[str]' instead">str</warning>)
|
||||
g2(<warning descr="Expected type 'T ≤: str', got 'type[str]' instead">str</warning>)
|
||||
|
||||
xs = list([str])
|
||||
|
||||
@@ -3,6 +3,6 @@ import my
|
||||
|
||||
def foo(a) -> my.X:
|
||||
if a:
|
||||
return <warning descr="Expected type 'X', got 'Type[X]' instead">my.X<caret></warning>
|
||||
return <warning descr="Expected type 'X', got 'type[X]' instead">my.X<caret></warning>
|
||||
else:
|
||||
return <warning descr="Expected type 'X', got 'Type[Y]' instead">my.Y</warning>
|
||||
return <warning descr="Expected type 'X', got 'type[Y]' instead">my.Y</warning>
|
||||
@@ -1,10 +1,8 @@
|
||||
from typing import Type
|
||||
|
||||
import my
|
||||
from my import X, Y
|
||||
|
||||
|
||||
def foo(a) -> Type[X | Y]:
|
||||
def foo(a) -> type[X | Y]:
|
||||
if a:
|
||||
return my.X<caret>
|
||||
else:
|
||||
|
||||
@@ -3,6 +3,6 @@ import my
|
||||
|
||||
def foo(a) -> my.X:
|
||||
if a:
|
||||
return <warning descr="Expected type 'X', got 'Type[X]' instead">my.X<caret></warning>
|
||||
return <warning descr="Expected type 'X', got 'type[X]' instead">my.X<caret></warning>
|
||||
else:
|
||||
return <warning descr="Expected type 'X', got 'Type[Y]' instead">my.Y</warning>
|
||||
return <warning descr="Expected type 'X', got 'type[Y]' instead">my.Y</warning>
|
||||
@@ -1,10 +1,8 @@
|
||||
from typing import Type
|
||||
|
||||
import my
|
||||
from my import X, Y
|
||||
|
||||
|
||||
def foo(a) -> Type[X | Y]:
|
||||
def foo(a) -> type[X | Y]:
|
||||
if a:
|
||||
return my.X
|
||||
else:
|
||||
|
||||
@@ -5,6 +5,6 @@ import my
|
||||
|
||||
def foo(a) -> my.X:
|
||||
if a:
|
||||
return <warning descr="Expected type 'X', got 'Type[X]' instead">my.X<caret></warning>
|
||||
return <warning descr="Expected type 'X', got 'type[X]' instead">my.X<caret></warning>
|
||||
else:
|
||||
return <warning descr="Expected type 'X', got 'Type[Y]' instead">my.Y</warning>
|
||||
return <warning descr="Expected type 'X', got 'type[Y]' instead">my.Y</warning>
|
||||
@@ -1,12 +1,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Type
|
||||
|
||||
import my
|
||||
from my import X, Y
|
||||
|
||||
|
||||
def foo(a) -> Type[X | Y]:
|
||||
def foo(a) -> type[X | Y]:
|
||||
if a:
|
||||
return my.X
|
||||
else:
|
||||
|
||||
@@ -3,6 +3,6 @@ import my
|
||||
|
||||
def foo(a) -> my.X:
|
||||
if a:
|
||||
return <warning descr="Expected type 'X', got 'Type[X]' instead">my.X<caret></warning>
|
||||
return <warning descr="Expected type 'X', got 'type[X]' instead">my.X<caret></warning>
|
||||
else:
|
||||
return <warning descr="Expected type 'X', got 'Type[Y]' instead">my.Y</warning>
|
||||
return <warning descr="Expected type 'X', got 'type[Y]' instead">my.Y</warning>
|
||||
@@ -1,10 +1,10 @@
|
||||
from typing import Union, Type
|
||||
from typing import Union
|
||||
|
||||
import my
|
||||
from my import X, Y
|
||||
|
||||
|
||||
def foo(a) -> Type[Union[X, Y]]:
|
||||
def foo(a) -> type[Union[X, Y]]:
|
||||
if a:
|
||||
return my.X
|
||||
else:
|
||||
|
||||
@@ -1 +1 @@
|
||||
<html><body><div class="bottom"><icon src="AllIcons.Nodes.Class"/> <code><a href="psi_element://#typename#ExplicitlyAnnotatedClsParamType.MyClass">ExplicitlyAnnotatedClsParamType.MyClass</a></code></div><div class="definition"><pre><span style="color:#808000;">@classmethod</span><br/><span style="color:#000080;font-weight:bold;">def </span><span style="color:#000000;">factory</span><span style="">(</span><span style="color:#94558d;">cls</span><span style="">: </span><span style="color:#000000;">Type<span style="">[</span>T<span style="">]</span></span><span style="">)</span> -> <span style="color:#000000;">T</span></pre></div></body></html>
|
||||
<html><body><div class="bottom"><icon src="AllIcons.Nodes.Class"/> <code><a href="psi_element://#typename#ExplicitlyAnnotatedClsParamType.MyClass">ExplicitlyAnnotatedClsParamType.MyClass</a></code></div><div class="definition"><pre><span style="color:#808000;">@classmethod</span><br/><span style="color:#000080;font-weight:bold;">def </span><span style="color:#000000;">factory</span><span style="">(</span><span style="color:#94558d;">cls</span><span style="">: </span><span style="color:#000000;"><span style="color:#000080;">type</span><span style="">[</span>T<span style="">]</span></span><span style="">)</span> -> <span style="color:#000000;">T</span></pre></div></body></html>
|
||||
@@ -1 +1 @@
|
||||
<html><body><div class="definition"><pre>Type alias statement <b>my_dict</b> of <a href="psi_element://#module#TypeAliasStatement">TypeAliasStatement</a><br/><span style="color:#000080;font-weight:bold;">type </span><span style="color:#000000;">my_dict</span><span style="">[</span><span style="color:#000000;">T</span><span style="">, </span><span style="color:#000000;">U</span><span style="">]</span><span style=""> = </span><span style="color:#000000;">Type<span style="">[</span><span style="color:#000080;"><a href="psi_element://#typename#dict">dict</a></span><span style="">[</span>T<span style="">, </span>U<span style="">]</span><span style="">]</span></span></pre></div></body></html>
|
||||
<html><body><div class="definition"><pre>Type alias statement <b>my_dict</b> of <a href="psi_element://#module#TypeAliasStatement">TypeAliasStatement</a><br/><span style="color:#000080;font-weight:bold;">type </span><span style="color:#000000;">my_dict</span><span style="">[</span><span style="color:#000000;">T</span><span style="">, </span><span style="color:#000000;">U</span><span style="">]</span><span style=""> = </span><span style="color:#000000;"><span style="color:#000080;">type</span><span style="">[</span><span style="color:#000080;"><a href="psi_element://#typename#dict">dict</a></span><span style="">[</span>T<span style="">, </span>U<span style="">]</span><span style="">]</span></span></pre></div></body></html>
|
||||
@@ -880,7 +880,7 @@ public class Py3TypeTest extends PyTestCase {
|
||||
|
||||
// PY-24445
|
||||
public void testIsSubclassInsideListComprehension() {
|
||||
doTest("list[Type[A]]",
|
||||
doTest("list[type[A]]",
|
||||
"class A: pass\n" +
|
||||
"expr = [e for e in [] if issubclass(e, A)]");
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ public class PyDecoratedFunctionTypeProviderTest extends PyTestCase {
|
||||
|
||||
// PY-60104
|
||||
public void testNotAnnotatedClassDecoratorIsIgnored() {
|
||||
doTest("C", "Type[C]", """
|
||||
doTest("C", "type[C]", """
|
||||
from typing import reveal_type
|
||||
|
||||
def changing_interface(cls):
|
||||
|
||||
@@ -273,16 +273,16 @@ public class PyParameterInfoTest extends LightMarkedTestCase {
|
||||
public void testRedefinedNewConstructorCall() {
|
||||
Map<String, PsiElement> marks = loadTest(2);
|
||||
|
||||
feignCtrlP(marks.get("<arg1>").getTextOffset()).check("cls: Type[A], a, b", new String[]{"a, "}, new String[]{"cls: Type[A], "});
|
||||
feignCtrlP(marks.get("<arg2>").getTextOffset()).check("cls: Type[A], a, b", new String[]{"b"}, new String[]{"cls: Type[A], "});
|
||||
feignCtrlP(marks.get("<arg1>").getTextOffset()).check("cls: type[A], a, b", new String[]{"a, "}, new String[]{"cls: type[A], "});
|
||||
feignCtrlP(marks.get("<arg2>").getTextOffset()).check("cls: type[A], a, b", new String[]{"b"}, new String[]{"cls: type[A], "});
|
||||
}
|
||||
|
||||
public void testRedefinedNewDirectCall() {
|
||||
Map<String, PsiElement> marks = loadTest(3);
|
||||
|
||||
feignCtrlP(marks.get("<arg1>").getTextOffset()).check("cls: Type[A], a, b", new String[]{"cls: Type[A], "});
|
||||
feignCtrlP(marks.get("<arg2>").getTextOffset()).check("cls: Type[A], a, b", new String[]{"a, "});
|
||||
feignCtrlP(marks.get("<arg3>").getTextOffset()).check("cls: Type[A], a, b", new String[]{"b"});
|
||||
feignCtrlP(marks.get("<arg1>").getTextOffset()).check("cls: type[A], a, b", new String[]{"cls: type[A], "});
|
||||
feignCtrlP(marks.get("<arg2>").getTextOffset()).check("cls: type[A], a, b", new String[]{"a, "});
|
||||
feignCtrlP(marks.get("<arg3>").getTextOffset()).check("cls: type[A], a, b", new String[]{"b"});
|
||||
}
|
||||
|
||||
public void testIgnoreNewInOldStyleClass() {
|
||||
|
||||
@@ -4014,7 +4014,7 @@ public class PyTypeTest extends PyTestCase {
|
||||
public void testParticularTypeAgainstTypeVarBoundedWithBuiltinType() {
|
||||
runWithLanguageLevel(
|
||||
LanguageLevel.getLatest(),
|
||||
() -> doTest("Type[MyClass]",
|
||||
() -> doTest("type[MyClass]",
|
||||
"""
|
||||
from typing import TypeVar, Type
|
||||
|
||||
|
||||
@@ -1245,7 +1245,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-20057
|
||||
public void testClassObjectType() {
|
||||
doTest("Type[MyClass]",
|
||||
doTest("type[MyClass]",
|
||||
"""
|
||||
from typing import Type
|
||||
|
||||
@@ -1258,7 +1258,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-20057
|
||||
public void testConstrainedClassObjectTypeOfParam() {
|
||||
doTest("Type[T]",
|
||||
doTest("type[T]",
|
||||
"""
|
||||
from typing import Type, TypeVar
|
||||
|
||||
@@ -1284,7 +1284,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-20057
|
||||
public void testFunctionReturnsTypeOfInstance() {
|
||||
doTest("Type[int]",
|
||||
doTest("type[int]",
|
||||
"""
|
||||
from typing import Type, TypeVar
|
||||
|
||||
@@ -1328,7 +1328,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-20057
|
||||
public void testUnionOfClassObjectTypes() {
|
||||
doTest("Type[int | str]",
|
||||
doTest("type[int | str]",
|
||||
"""
|
||||
from typing import Type, Union
|
||||
|
||||
@@ -1338,7 +1338,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-23053
|
||||
public void testUnboundGenericMatchesClassObjectTypes() {
|
||||
doTest("Type[str]",
|
||||
doTest("type[str]",
|
||||
"""
|
||||
from typing import Generic, TypeVar
|
||||
|
||||
@@ -1357,7 +1357,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-23053
|
||||
public void testListContainingClasses() {
|
||||
doTest("Type[str]",
|
||||
doTest("type[str]",
|
||||
"xs = [str]\n" +
|
||||
"expr = xs.pop()");
|
||||
}
|
||||
@@ -1962,7 +1962,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-44974
|
||||
public void testBitwiseOrUnionIsSubclass() {
|
||||
doTest("Type[str | dict | int]",
|
||||
doTest("type[str | dict | int]",
|
||||
"""
|
||||
a = list
|
||||
if issubclass(a, str | dict | int):
|
||||
@@ -1971,7 +1971,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-79861
|
||||
public void testWalrusIsSubclass() {
|
||||
doTest("Type[str | dict | int]",
|
||||
doTest("type[str | dict | int]",
|
||||
"""
|
||||
if issubclass(a := list, str | dict | int):
|
||||
expr = a""");
|
||||
@@ -1979,7 +1979,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-79861
|
||||
public void testWalrusCallable() {
|
||||
doTest("Type[Callable]",
|
||||
doTest("type[Callable]",
|
||||
"""
|
||||
if callable(a := 42):
|
||||
expr = a""");
|
||||
@@ -4626,7 +4626,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-71002
|
||||
public void testTypeVarDefaultsClassReference() {
|
||||
doTest("Type[slice[int, int, int | None]]", """
|
||||
doTest("type[slice[int, int, int | None]]", """
|
||||
from typing import TypeVar, Generic
|
||||
StartT = TypeVar("StartT", default=int)
|
||||
StopT = TypeVar("StopT", default=StartT)
|
||||
@@ -4638,7 +4638,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-71002
|
||||
public void testTypeVarDefaultsClassReferenceNewSyntax() {
|
||||
doTest("Type[slice[int, int, int | None]]", """
|
||||
doTest("type[slice[int, int, int | None]]", """
|
||||
class slice[StartT = int, StopT = StartT, StepT = int | None]: ...
|
||||
expr = slice
|
||||
""");
|
||||
@@ -4706,7 +4706,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-71002
|
||||
public void testTypeVarDefaultsListDefault() {
|
||||
doTest("Type[Bar[int, list[int]]]", """
|
||||
doTest("type[Bar[int, list[int]]]", """
|
||||
from typing import TypeVar, Generic
|
||||
|
||||
T = TypeVar("T")
|
||||
@@ -4721,7 +4721,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-71002
|
||||
public void testTypeVarDefaultsClassWithInitMethodReference() {
|
||||
doTest("Type[Bar[Any, list]]", """
|
||||
doTest("type[Bar[Any, list]]", """
|
||||
from typing import TypeVar, Generic
|
||||
Z1 = TypeVar("Z1")
|
||||
ListDefaultT = TypeVar("ListDefaultT", default=list[Z1])
|
||||
@@ -4733,7 +4733,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-71002
|
||||
public void testTypeVarDefaultsClassWithInitMethodReferenceNewSyntax() {
|
||||
doTest("Type[Bar[Any, list]]", """
|
||||
doTest("type[Bar[Any, list]]", """
|
||||
from typing import TypeVar, Generic
|
||||
class Bar[Z1, ListDefaultT = list[Z1]]:
|
||||
def __init__(self, x: Z1, y: ListDefaultT): ...
|
||||
@@ -4743,7 +4743,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-71002
|
||||
public void testTypeVarDefaultsClassWithInitMethodReferenceParameterizedWithOneType() {
|
||||
doTest("Type[Bar[int, list[int]]]", """
|
||||
doTest("type[Bar[int, list[int]]]", """
|
||||
from typing import TypeVar, Generic
|
||||
Z1 = TypeVar("Z1")
|
||||
ListDefaultT = TypeVar("ListDefaultT", default=list[Z1])
|
||||
@@ -4791,7 +4791,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-71002
|
||||
public void testTypeVarDefaultsSubclassedClassReference() {
|
||||
doTest("Type[Bar[str]]", """
|
||||
doTest("type[Bar[str]]", """
|
||||
from typing import TypeVar, Generic, TypeAlias
|
||||
T1 = TypeVar("T1")
|
||||
T2 = TypeVar("T2")
|
||||
@@ -4847,7 +4847,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-71002
|
||||
public void testReferenceToTypeVarTupleWithDefaultIsParameterizedType() {
|
||||
doTest("Type[Foo[str, int]]", """
|
||||
doTest("type[Foo[str, int]]", """
|
||||
from typing import Generic, TypeVarTuple, Unpack
|
||||
DefaultTs = TypeVarTuple("DefaultTs", default=Unpack[tuple[str, int]])
|
||||
class Foo(Generic[*DefaultTs]): ...
|
||||
@@ -4897,7 +4897,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-71002
|
||||
public void testParamSpecWithDefaultsClassReference() {
|
||||
doTest("Type[Foo[[str, int]]]", """
|
||||
doTest("type[Foo[[str, int]]]", """
|
||||
from typing import ParamSpec, Generic
|
||||
DefaultP = ParamSpec("DefaultP", default=[str, int])
|
||||
class Foo(Generic[DefaultP]): ...
|
||||
@@ -4907,7 +4907,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-71002
|
||||
public void testParamSpecWithDefaultsClassReferencesNewSyntax() {
|
||||
doTest("Type[Foo[[str, int]]]", """
|
||||
doTest("type[Foo[[str, int]]]", """
|
||||
class Foo[**P = [str, int]]: ...
|
||||
expr = Foo
|
||||
""");
|
||||
@@ -5128,7 +5128,7 @@ public class PyTypingTest extends PyTestCase {
|
||||
|
||||
// PY-71002
|
||||
public void testMixedTypeVarsWithDefaultsAndNonDefaultsReferenceType() {
|
||||
doTest("Type[AllTheDefaults[int, complex, str, int, bool]]", """
|
||||
doTest("type[AllTheDefaults[int, complex, str, int, bool]]", """
|
||||
from typing import TypeVar, Generic
|
||||
T1 = TypeVar("T1")
|
||||
T2 = TypeVar("T2")
|
||||
|
||||
@@ -863,7 +863,7 @@ public class Py3TypeCheckerInspectionTest extends PyInspectionTestCase {
|
||||
from typing import Type
|
||||
def foo(x: Type[int | str]):
|
||||
pass
|
||||
foo(<warning descr="Expected type 'Type[int | str]', got 'UnionType' instead">int | str</warning>)""");
|
||||
foo(<warning descr="Expected type 'type[int | str]', got 'UnionType' instead">int | str</warning>)""");
|
||||
}
|
||||
|
||||
// PY-44974
|
||||
@@ -2482,7 +2482,7 @@ def foo(param: str | int) -> TypeGuard[str]:
|
||||
t = Test()
|
||||
t.member = "str"
|
||||
t.member = <warning descr="Expected type 'str' (from '__set__'), got 'int' instead">123</warning>
|
||||
t.member = <warning descr="Expected type 'str' (from '__set__'), got 'Type[list]' instead">list</warning>
|
||||
t.member = <warning descr="Expected type 'str' (from '__set__'), got 'type[list]' instead">list</warning>
|
||||
""");
|
||||
}
|
||||
|
||||
@@ -2500,7 +2500,7 @@ def foo(param: str | int) -> TypeGuard[str]:
|
||||
t = Test()
|
||||
t.member = "str"
|
||||
t.member = <warning descr="Expected type 'str' (from '__set__'), got 'int' instead">123</warning>
|
||||
t.member = <warning descr="Expected type 'str' (from '__set__'), got 'Type[list]' instead">list</warning>
|
||||
t.member = <warning descr="Expected type 'str' (from '__set__'), got 'type[list]' instead">list</warning>
|
||||
""");
|
||||
}
|
||||
|
||||
|
||||
@@ -1219,7 +1219,7 @@ public class PyTypeCheckerInspectionTest extends PyInspectionTestCase {
|
||||
def some_fn(arg: B):
|
||||
pass
|
||||
|
||||
some_fn(<warning descr="Expected type 'B', got 'Type[B]' instead">B</warning>)""")
|
||||
some_fn(<warning descr="Expected type 'B', got 'type[B]' instead">B</warning>)""")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1112,12 +1112,12 @@ public class PyTypeHintsInspectionTest extends PyInspectionTestCase {
|
||||
# cls is not specified\s
|
||||
@classmethod
|
||||
def spam3(cls):
|
||||
<warning descr="The type of self 'int' is not a supertype of its class 'Type[Bar]'"># type: (int) -> None</warning>
|
||||
<warning descr="The type of self 'int' is not a supertype of its class 'type[Bar]'"># type: (int) -> None</warning>
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def egg3(cls, a, b):
|
||||
<warning descr="The type of self 'int' is not a supertype of its class 'Type[Bar]'"># type: (int, str, bool) -> None</warning>
|
||||
<warning descr="The type of self 'int' is not a supertype of its class 'type[Bar]'"># type: (int, str, bool) -> None</warning>
|
||||
pass
|
||||
\s
|
||||
# cls is specified \s
|
||||
|
||||
@@ -37,25 +37,25 @@ public class PyMakeFunctionReturnTypeQuickFixTest extends PyQuickFixTestCase {
|
||||
// PY-27128
|
||||
public void testPy39UnionTypeImports() {
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON39, () -> {
|
||||
doMultiFileTest(PyTypeCheckerInspection.class, PyPsiBundle.message("QFIX.make.function.return.type", "foo", "Type[Union[X, Y]]"));
|
||||
doMultiFileTest(PyTypeCheckerInspection.class, PyPsiBundle.message("QFIX.make.function.return.type", "foo", "type[Union[X, Y]]"));
|
||||
});
|
||||
}
|
||||
|
||||
// PY-27128
|
||||
public void testPy39BitwiseOrUnionFromFutureAnnotationsUnionTypeImports() {
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON39, () -> {
|
||||
doMultiFileTest(PyTypeCheckerInspection.class, PyPsiBundle.message("QFIX.make.function.return.type", "foo", "Type[X | Y]"));
|
||||
doMultiFileTest(PyTypeCheckerInspection.class, PyPsiBundle.message("QFIX.make.function.return.type", "foo", "type[X | Y]"));
|
||||
});
|
||||
}
|
||||
|
||||
// PY-27128
|
||||
public void testBitwiseOrUnionTypeImports() {
|
||||
doMultiFileTest(PyTypeCheckerInspection.class, PyPsiBundle.message("QFIX.make.function.return.type", "foo", "Type[X | Y]"));
|
||||
doMultiFileTest(PyTypeCheckerInspection.class, PyPsiBundle.message("QFIX.make.function.return.type", "foo", "type[X | Y]"));
|
||||
}
|
||||
|
||||
// PY-27128
|
||||
public void testAncestorAndInheritorReturn() {
|
||||
doMultiFileTest(PyTypeCheckerInspection.class, PyPsiBundle.message("QFIX.make.function.return.type", "foo", "Type[X | Y]"));
|
||||
doMultiFileTest(PyTypeCheckerInspection.class, PyPsiBundle.message("QFIX.make.function.return.type", "foo", "type[X | Y]"));
|
||||
}
|
||||
|
||||
// PY-27128 PY-48466
|
||||
|
||||
Reference in New Issue
Block a user