@@ -104,6 +104,10 @@ def _type_check_with_pyright(cls, code: str) -> TypeCheckResult:
104
104
if token .type == tokenize .COMMENT
105
105
and token .string [1 :].strip () == cls .EXPECT_ERROR_COMMENT
106
106
]
107
+ # Tracks whether an expected error has been reported by type checker.
108
+ error_line_seen_in_err_msg : dict [int , bool ] = {
109
+ lineno : False for lineno in expect_error_line_numbers
110
+ }
107
111
108
112
with tempfile .NamedTemporaryFile (suffix = ".py" ) as temp :
109
113
temp .write (code .encode ())
@@ -122,19 +126,20 @@ def _type_check_with_pyright(cls, code: str) -> TypeCheckResult:
122
126
if m is None :
123
127
continue
124
128
line_number , message = int (m .group (1 )), m .group (2 )
125
- if line_number in expect_error_line_numbers :
129
+ if line_number in error_line_seen_in_err_msg :
126
130
# Each reported error should be attached to a specific line,
127
131
# If it is commented with # expect-type-error, let it pass.
128
- expect_error_line_numbers . remove ( line_number )
132
+ error_line_seen_in_err_msg [ line_number ] = True
129
133
continue
130
134
error_lines .append (f"{ line_number } :{ message } " )
131
135
132
136
# If there are any lines that are expected to fail but not reported by pyright,
133
137
# they should be considered as errors.
134
- for line_number in expect_error_line_numbers :
135
- error_lines .append (
136
- f"{ line_number } : error: Expected type error but instead passed"
137
- )
138
+ for line_number , seen in error_line_seen_in_err_msg .items ():
139
+ if not seen :
140
+ error_lines .append (
141
+ f"{ line_number } : error: Expected type error but instead passed"
142
+ )
138
143
139
144
passed = len (error_lines ) == 0
140
145
if passed :
0 commit comments