Skip to content

Commit eb92319

Browse files
committed
move the new test cases from check-classes.test to check-mangling.text
1 parent 89d11a6 commit eb92319

File tree

2 files changed

+277
-278
lines changed

2 files changed

+277
-278
lines changed

test-data/unit/check-classes.test

Lines changed: 0 additions & 278 deletions
Original file line numberDiff line numberDiff line change
@@ -8465,281 +8465,3 @@ def deco(fn: Callable[[], list[T]]) -> Callable[[], T]: ...
84658465
@deco
84668466
def f() -> list[str]: ...
84678467
[builtins fixtures/property.pyi]
8468-
8469-
[case testNameManglingAttribute]
8470-
8471-
class A:
8472-
__x: int
8473-
8474-
def __init__(self) -> None:
8475-
self.__y: int
8476-
self._A__z: int
8477-
8478-
def get(self) -> None:
8479-
reveal_type(self.__x) # N: Revealed type is "builtins.int"
8480-
reveal_type(self._A__x) # N: Revealed type is "builtins.int"
8481-
reveal_type(self.__y) # N: Revealed type is "builtins.int"
8482-
reveal_type(self._A__y) # N: Revealed type is "builtins.int"
8483-
reveal_type(self.__z) # N: Revealed type is "builtins.int"
8484-
reveal_type(self._A__z) # N: Revealed type is "builtins.int"
8485-
8486-
def set(self) -> None:
8487-
self.__x = "" # E: Incompatible types in assignment (expression has type "str", variable has type "int")
8488-
self._A__x = "" # E: Incompatible types in assignment (expression has type "str", variable has type "int")
8489-
self.__y += "" # E: Unsupported operand types for + ("int" and "str")
8490-
self._A__y += "" # E: Unsupported operand types for + ("int" and "str")
8491-
self.__z = "" # E: Incompatible types in assignment (expression has type "str", variable has type "int")
8492-
self._A__z = "" # E: Incompatible types in assignment (expression has type "str", variable has type "int")
8493-
8494-
class B(A):
8495-
__x: str
8496-
8497-
def __init__(self) -> None:
8498-
self.__y: str
8499-
self._A__z: str # E: Incompatible types in assignment (expression has type "str", base class "A" defined the type as "int")
8500-
8501-
def get(self) -> None:
8502-
reveal_type(self.__x) # N: Revealed type is "builtins.str"
8503-
reveal_type(self._A__x) # N: Revealed type is "builtins.int"
8504-
reveal_type(self._B__x) # N: Revealed type is "builtins.str"
8505-
reveal_type(self.__y) # N: Revealed type is "builtins.str"
8506-
reveal_type(self._A__y) # N: Revealed type is "builtins.int"
8507-
reveal_type(self._B__y) # N: Revealed type is "builtins.str"
8508-
self.__z # E: "B" has no attribute "_B__z"; maybe "_A__z", "_B__x", or "_B__y"?
8509-
reveal_type(self._A__z) # N: Revealed type is "builtins.str"
8510-
self._B__z # E: "B" has no attribute "_B__z"; maybe "_A__z", "_B__x", or "_B__y"?
8511-
8512-
[case testNameManglingMethod]
8513-
8514-
class A:
8515-
8516-
def __f(self) -> int:
8517-
...
8518-
8519-
def g(self) -> None:
8520-
reveal_type(self.__f()) # N: Revealed type is "builtins.int"
8521-
reveal_type(self._A__f()) # N: Revealed type is "builtins.int"
8522-
8523-
async def __h(self) -> int:
8524-
...
8525-
8526-
async def i(self) -> None:
8527-
await reveal_type(self.__h()) # N: Revealed type is "typing.Coroutine[Any, Any, builtins.int]"
8528-
await reveal_type(self._A__h()) # N: Revealed type is "typing.Coroutine[Any, Any, builtins.int]"
8529-
8530-
class B(A):
8531-
8532-
def j(self) -> None:
8533-
reveal_type(self._A__f()) # N: Revealed type is "builtins.int"
8534-
self.__f() # E: "B" has no attribute "_B__f"; maybe "_A__f"?
8535-
self._B__f() # E: "B" has no attribute "_B__f"; maybe "_A__f"?
8536-
8537-
async def k(self) -> None:
8538-
await reveal_type(self._A__h()) # N: Revealed type is "typing.Coroutine[Any, Any, builtins.int]"
8539-
self.__h() # E: "B" has no attribute "_B__h"; maybe "_A__h"?
8540-
self._B__h() # E: "B" has no attribute "_B__h"; maybe "_A__h"?
8541-
8542-
class C(B):
8543-
8544-
def __f(self) -> str:
8545-
...
8546-
8547-
def _A__f(self) -> str: # E: Return type "str" of "_A__f" incompatible with return type "int" in supertype "A"
8548-
...
8549-
8550-
async def __h(self) -> str:
8551-
...
8552-
8553-
async def _A__h(self) -> str: # E: Return type "Coroutine[Any, Any, str]" of "_A__h" incompatible with return type "Coroutine[Any, Any, int]" in supertype "A"
8554-
...
8555-
8556-
[case testNameManglingDecorator]
8557-
from typing import Callable, Protocol, Type
8558-
8559-
class FuncWrapper(Protocol):
8560-
def __call__(__self, f: Callable[[A], int]) -> Callable[[A], str]: ...
8561-
def decorator_func(string: str) -> FuncWrapper: ...
8562-
8563-
class ClassModifier(Protocol):
8564-
def __call__(__self, c: Type[A._A__B]) -> Type[A._A__B]: ...
8565-
def decorator_class(string: str) -> ClassModifier: ...
8566-
8567-
class A:
8568-
__x: str = "test"
8569-
8570-
@decorator_func(__x)
8571-
def __wrapped(self) -> int: ...
8572-
8573-
@decorator_class(__x)
8574-
class __B: ...
8575-
8576-
a: A
8577-
a.__wrapped() # E: "A" has no attribute "__wrapped"; maybe "_A__wrapped"?
8578-
reveal_type(a._A__wrapped()) # N: Revealed type is "builtins.str"
8579-
a.__B # E: "A" has no attribute "__B"
8580-
reveal_type(a._A__B) # N: Revealed type is "def () -> __main__.A._A__B"
8581-
8582-
[case testNameManglingNestedClass]
8583-
8584-
class A:
8585-
class __B:
8586-
__y: int
8587-
8588-
def __g(self) -> str:
8589-
reveal_type(self.__y) # N: Revealed type is "builtins.int"
8590-
reveal_type(self._B__y) # N: Revealed type is "builtins.int"
8591-
return "x"
8592-
8593-
reveal_type(__g) # N: Revealed type is "def (self: __main__.A._A__B) -> builtins.str"
8594-
reveal_type(_B__g) # N: Revealed type is "def (self: __main__.A._A__B) -> builtins.str"
8595-
8596-
__x: int
8597-
8598-
def __f(self) -> float:
8599-
reveal_type(self.__x) # N: Revealed type is "builtins.int"
8600-
reveal_type(self._A__x) # N: Revealed type is "builtins.int"
8601-
b = self.__B()
8602-
b.__y # E: "_A__B" has no attribute "_A__y"; maybe "_B__y"?
8603-
b._A__y # E: "_A__B" has no attribute "_A__y"; maybe "_B__y"?
8604-
reveal_type(b._B__y) # N: Revealed type is "builtins.int"
8605-
return 1.0
8606-
8607-
reveal_type(__f) # N: Revealed type is "def (self: __main__.A) -> builtins.float"
8608-
reveal_type(_A__f) # N: Revealed type is "def (self: __main__.A) -> builtins.float"
8609-
8610-
[case testNameManglingInheritance]
8611-
8612-
class __A: ...
8613-
class B(__A): ...
8614-
8615-
import enum as __enum
8616-
class C(__enum.Flag): ...
8617-
[builtins fixtures/tuple.pyi]
8618-
8619-
[case testNameManglingAnnotationsPast]
8620-
from typing import Generic, TypeVar
8621-
8622-
__T = TypeVar("__T")
8623-
8624-
class A(Generic[__T]):
8625-
__x: __T # E: Name "_A__T" is not defined
8626-
8627-
__y = int
8628-
class __B:
8629-
def f1(self, a: A[int]) -> __y: # E: Name "_B__y" is not defined
8630-
a.__x # E: "A[int]" has no attribute "_B__x"; maybe "_A__x"?
8631-
8632-
def f2(self, a: A) -> "__y":
8633-
a.__x # E: "A[Any]" has no attribute "_B__x"; maybe "_A__x"?
8634-
return 1
8635-
8636-
class C:
8637-
b1: __B # E: Name "_C__B" is not defined
8638-
b2: "__B"
8639-
8640-
def f1(self, __x: __y, __z: int) -> None: # E: Name "_C__y" is not defined
8641-
reveal_type(__z) # N: Revealed type is "builtins.int"
8642-
8643-
def f2(self, __x: "__y", __z: "int") -> None:
8644-
reveal_type(__x) # N: Revealed type is "builtins.int"
8645-
reveal_type(__z) # N: Revealed type is "builtins.int"
8646-
8647-
reveal_type(C().b2) # N: Revealed type is "__main__.__B"
8648-
8649-
[case testNameManglingAnnotationsFuture]
8650-
from __future__ import annotations
8651-
from typing import Generic, TypeVar
8652-
8653-
__T = TypeVar("__T")
8654-
class A(Generic[__T]):
8655-
__x: __T
8656-
8657-
__y = int
8658-
class __B:
8659-
def f1(self, a: A[int]) -> __y:
8660-
a.__x # E: "A[int]" has no attribute "_B__x"; maybe "_A__x"?
8661-
return 1
8662-
8663-
def f2(self, a: A) -> "__y":
8664-
a.__x # E: "A[Any]" has no attribute "_B__x"; maybe "_A__x"?
8665-
return 1
8666-
8667-
class C:
8668-
b1: __B
8669-
b2: "__B"
8670-
8671-
def f1(self, __x: __y, __z: int) -> None:
8672-
reveal_type(__x) # N: Revealed type is "builtins.int"
8673-
reveal_type(__z) # N: Revealed type is "builtins.int"
8674-
8675-
def f2(self, __x: "__y", __z: "int") -> None:
8676-
reveal_type(__x) # N: Revealed type is "builtins.int"
8677-
reveal_type(__z) # N: Revealed type is "builtins.int"
8678-
8679-
reveal_type(C().b1) # N: Revealed type is "__main__.__B"
8680-
reveal_type(C().b2) # N: Revealed type is "__main__.__B"
8681-
[builtins fixtures/tuple.pyi]
8682-
8683-
[case testNameManglingSlots]
8684-
8685-
class A:
8686-
__slots__ = ["__x"]
8687-
8688-
def __init__(self) -> None:
8689-
self.__x = 1
8690-
8691-
A().__x = 1 # E: "A" has no attribute "__x"
8692-
A()._A__x = 1
8693-
8694-
class B(A):
8695-
def __init__(self) -> None:
8696-
self.__x = 1
8697-
8698-
B().__x = 1 # E: "B" has no attribute "__x"
8699-
B()._B__x = 1
8700-
8701-
class C(A):
8702-
__slots__ = []
8703-
8704-
def __init__(self) -> None:
8705-
self.__x = 1 # E: Trying to assign name "_C__x" that is not in "__slots__" of type "__main__.C"
8706-
8707-
C().__x = 1 # E: "C" has no attribute "__x"
8708-
C()._C__x = 1 # E: Trying to assign name "_C__x" that is not in "__slots__" of type "__main__.C"
8709-
8710-
class D(A):
8711-
__slots__ = ["__x"]
8712-
8713-
def __init__(self) -> None:
8714-
self.__x = 1
8715-
8716-
D().__x = 1 # E: "D" has no attribute "__x"
8717-
D()._D__x = 1
8718-
8719-
class E(A):
8720-
__slots__ = ("__x",)
8721-
8722-
def __init__(self) -> None:
8723-
self.__x = 1
8724-
8725-
E().__x = 1 # E: "E" has no attribute "__x"
8726-
E()._E__x = 1
8727-
8728-
class F(A):
8729-
__slots__ = "__x"
8730-
8731-
def __init__(self) -> None:
8732-
self.__x = 1
8733-
8734-
F().__x = 1 # E: "F" has no attribute "__x"
8735-
F()._F__x = 1
8736-
8737-
class G(A):
8738-
__slots__ = {"__x": "docstring"}
8739-
8740-
def __init__(self) -> None:
8741-
self.__x = 1
8742-
8743-
G().__x = 1 # E: "G" has no attribute "__x"
8744-
G()._G__x = 1
8745-
[builtins fixtures/dict.pyi]

0 commit comments

Comments
 (0)