mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-84570 Do not consider bare list literal as a valid type alias
(cherry picked from commit f0bcd2445735caa7917944351140a2877d0b4ffe) GitOrigin-RevId: 5f0a0bff41ee01b4e8b4f7e73c1062d523854c2c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3b8f47d347
commit
fcf1abdbb7
+9
@@ -183,6 +183,15 @@ public final class PyTypingAliasStubType extends CustomTargetExpressionStubType<
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyListLiteralExpression(@NotNull PyListLiteralExpression node) {
|
||||
if (node == expression) {
|
||||
illegal[0] = true;
|
||||
return;
|
||||
}
|
||||
super.visitElement(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitElement(@NotNull PsiElement element) {
|
||||
if (element instanceof ASTDelegatePsiElement) {
|
||||
|
||||
@@ -20,6 +20,9 @@ bin1_ok = int | str
|
||||
bin2_ok = int | str | bool | None
|
||||
bin3_ok = Union[str, bool] | None
|
||||
bin4_notOk = str & int
|
||||
list_notOk = [int, str]
|
||||
|
||||
callable_ok = Callable[[int, str], bool]
|
||||
|
||||
explicit_alias1_ok: TypeAlias = 'Foo is bar.'
|
||||
explicit_alias2_ok = 'Foo is bar.' # type: TypeAlias
|
||||
|
||||
@@ -3169,6 +3169,26 @@ public class PyTypeHintsInspectionTest extends PyInspectionTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
// PY-84570
|
||||
public void testListLiteralIsNotConsideredTypeAlias() {
|
||||
doTestByText("""
|
||||
from enum import Enum
|
||||
from typing import TypeAlias
|
||||
|
||||
class Direction(Enum):
|
||||
NORTH = "N"
|
||||
SOUTH = "S"
|
||||
EAST = "E"
|
||||
WEST = "W"
|
||||
|
||||
CARTESIAN = [Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST]
|
||||
print(CARTESIAN[0])
|
||||
|
||||
type Alias = <warning descr="Type hint is invalid or refers to the expression which is not a correct type">[int, str]</warning>
|
||||
myAlias: TypeAlias = <warning descr="Assigned value of type alias must be a correct type">[int, str]</warning>
|
||||
""");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Class<? extends PyInspection> getInspectionClass() {
|
||||
|
||||
Reference in New Issue
Block a user