mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-84538 Report protocol instantiation as an error
(cherry picked from commit ad941a5d9a5fb852b0c28cbf259fdcc5ce3f3efb) IJ-MR-173617 GitOrigin-RevId: 97c2b967b5a2c42d0f1c6c5f09a65beb64bd634c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
db45df3fd6
commit
96a0d7da31
@@ -44,6 +44,69 @@ public class PyProtocolInspectionTest extends PyInspectionTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
// PY-76903
|
||||
public void testProtocolCannotBeInstantiated() {
|
||||
doTestByText("""
|
||||
from typing import Protocol
|
||||
|
||||
class P(Protocol):
|
||||
...
|
||||
|
||||
p = <warning descr="Cannot instantiate protocol class 'P'">P()</warning>
|
||||
""");
|
||||
}
|
||||
|
||||
// PY-76903
|
||||
public void testProtocolSubclassCanBeInstantiated() {
|
||||
doTestByText("""
|
||||
from typing import Protocol
|
||||
|
||||
class P(Protocol):
|
||||
...
|
||||
|
||||
|
||||
class C(P):
|
||||
...
|
||||
|
||||
c = C()
|
||||
""");
|
||||
}
|
||||
|
||||
// PY-76903
|
||||
public void testProtocolFunctionCall() {
|
||||
doTestByText("""
|
||||
from typing import Protocol
|
||||
|
||||
class P(Protocol):
|
||||
def foo(self) -> None: ...
|
||||
|
||||
|
||||
def f(p: P):
|
||||
p.foo()
|
||||
""");
|
||||
}
|
||||
|
||||
// PY-76903
|
||||
public void testProtocolTypeButConcreteValue() {
|
||||
doTestByText("""
|
||||
from typing import Protocol, reveal_type
|
||||
|
||||
class P(Protocol):
|
||||
def foo(self) -> None: ...
|
||||
|
||||
|
||||
class I(P):
|
||||
def foo(self) -> None: ...
|
||||
|
||||
|
||||
def f() -> type[P]:
|
||||
return I
|
||||
|
||||
t = f()
|
||||
t()
|
||||
""");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doTest() {
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON37, () -> super.doTest());
|
||||
|
||||
Reference in New Issue
Block a user