Skip to content

Commit 796adda

Browse files
fix broken tests, elaborate on test file format in the readme
1 parent a429c05 commit 796adda

File tree

6 files changed

+27
-15
lines changed

6 files changed

+27
-15
lines changed

test-data/unit/README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,23 @@ with text "abc..."
3131
- note a space after `E:` and `flags:`
3232
- `# E:12` adds column number to the expected error
3333
- use `\` to escape the `#` character and indicate that the rest of the line is part of
34-
the error message (note that there is no support for using `\\` to escape a backslash itself)
34+
the error message (note that there is no support for using `\\` to escape a backslash itself
35+
in this context; also, in all other contexts, such as line-continuation, the backslash is treated
36+
as it normally would be in a python source file)
3537
- repeating `# E: ` several times in one line indicates multiple expected errors in one line
3638
- `W: ...` and `N: ...` works exactly like `E: ...`, but report a warning and a note respectively
3739
- lines that don't contain the above should cause no type check errors
40+
- lines that begin with `--` are test-file-format comments, and will not appear in the texted python
41+
source code
42+
- some test files are run in a special way by the test runner; this is typically documented in
43+
test-file-format comments at the top of the test file
3844
- optional `[builtins fixtures/...]` tells the type checker to use
3945
`builtins` stubs from the indicated file (see Fixtures section below)
4046
- optional `[out]` is an alternative to the `# E: ` notation: it indicates that
41-
any text after it contains the expected type checking error messages.
42-
Usually, `# E: ` is preferred because it makes it easier to associate the
43-
errors with the code generating them at a glance, and to change the code of
44-
the test without having to change line numbers in `[out]`
47+
any text after it contains the expected type checking error messages.
48+
Usually, `# E: ` is preferred because it makes it easier to associate the
49+
errors with the code generating them at a glance, and to change the code of
50+
the test without having to change line numbers in `[out]`
4551
- an empty `[out]` section has no effect
4652
- to add tests for a feature that hasn't been implemented yet, append `-xfail`
4753
to the end of the test name

test-data/unit/check-classes.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ class A:
695695
def __replace__(self, x: Optional[str]) -> Self: pass
696696

697697
class B(A):
698-
def __replace__(self, x: str) -> Self: pass # E: \
698+
def __replace__(self, x: str) -> Self: pass \
699699
# E: Argument 1 of "__replace__" is incompatible with supertype "A"; supertype defines the argument type as "Optional[str]" [override] \
700700
# N: This violates the Liskov substitution principle \
701701
# N: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides

test-data/unit/check-deprecated.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ from typing_extensions import deprecated
4949
@deprecated("use f2 instead")
5050
def f() -> None: ...
5151

52-
f # E: function __main__.f is deprecated: use f2 instead # type: ignore[deprecated]
52+
f # type: ignore[deprecated]
53+
f # E: function __main__.f is deprecated: use f2 instead
5354
f(1) # E: function __main__.f is deprecated: use f2 instead \
5455
# E: Too many arguments for "f"
5556
f[1] # E: function __main__.f is deprecated: use f2 instead \

test-data/unit/check-newsemanal.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2684,7 +2684,7 @@ class C:
26842684
) -> str:
26852685
return 0 # E: Incompatible return value type (got "int", expected "str")
26862686

2687-
reveal_type(C.X) # E: # N: Revealed type is "def () -> __main__.X"
2687+
reveal_type(C.X) # N: Revealed type is "def () -> __main__.X"
26882688
reveal_type(C().str()) # N: Revealed type is "builtins.str"
26892689

26902690
[case testNewAnalyzerNameNotDefinedYetInClassBody]

test-data/unit/check-type-aliases.test

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -551,12 +551,7 @@ def take_id(x: Id[int]) -> None:
551551
def id(x: Id[T]) -> T:
552552
return x
553553

554-
# TODO: This doesn't work and maybe it should?
555-
# Indirection = AnInt[T]
556-
# y: Indirection[str]
557-
# reveal_type(y) # E : Revealed type is "builtins.int"
558-
559-
# But this does
554+
# Contrast with the TODO below
560555
Indirection2 = FlexibleAlias[T, AnInt[T]]
561556
z: Indirection2[str]
562557
reveal_type(z) # N: Revealed type is "builtins.int"
@@ -567,6 +562,16 @@ reveal_type(w) # N: Revealed type is "builtins.int"
567562

568563
[builtins fixtures/dict.pyi]
569564

565+
[case testFlexibleAlias1Todo-xfail]
566+
# TODO: This doesn't work and maybe it should?
567+
# Contrast with the example above that mentions this todo
568+
T = TypeVar('T')
569+
AnInt = FlexibleAlias[T, int]
570+
Indirection = AnInt[T]
571+
y: Indirection[str]
572+
reveal_type(y) # N : Revealed type is "builtins.int"
573+
574+
570575
[case testFlexibleAlias2]
571576
# flags: --always-true=BOGUS
572577
from typing import TypeVar, Any

test-data/unit/check-typeddict.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3652,7 +3652,7 @@ reveal_type(X) # N: Revealed type is "builtins.dict[builtins.str, def () -> bui
36523652
from typing_extensions import TypeAlias
36533653
X: TypeAlias = {"int": int, "str": str}
36543654
x: X
3655-
reveal_type(x) # N: # N: Revealed type is "TypedDict({'int': builtins.int, 'str': builtins.str})"
3655+
reveal_type(x) # N: Revealed type is "TypedDict({'int': builtins.int, 'str': builtins.str})"
36563656
[builtins fixtures/dict.pyi]
36573657
[typing fixtures/typing-typeddict.pyi]
36583658

0 commit comments

Comments
 (0)