[inspections] PY-85120 Do not consider expressions like a: list[int] | None = None a type alias

Target expression should have either explicit `TypeAlias` annotation or valid type expression in assignment without type annotation (to be considered implicit type alias)

(cherry picked from commit 1059a8df2d221bd068eee706139be20c256df549)

GitOrigin-RevId: 8c952138fbc4124f02f717ce8a1784c1f0dc86b2
This commit is contained in:
Daniil Kalinin
2025-11-03 10:33:56 +00:00
committed by intellij-monorepo-bot
parent 1b197eb884
commit 489b9b90aa
4 changed files with 15 additions and 2 deletions
@@ -3189,6 +3189,16 @@ public class PyTypeHintsInspectionTest extends PyInspectionTestCase {
""");
}
// PY-85120
public void testTargetExpressionWithAnnotationNotConsideredTypeAlias() {
doTestByText("""
a: list[int] | None = None # Not a type alias
if a:
_ = a[1] # No error expected
""");
}
@NotNull
@Override
protected Class<? extends PyInspection> getInspectionClass() {