@@ -211,6 +211,99 @@ enable_error_code = ignore-without-code, truthy-bool
211211\[mypy-tests.*]
212212disable_error_code = ignore-without-code
213213
214+ [case testInlineErrorCodesOverrideConfigSmall]
215+ # flags: --config-file tmp/mypy.ini
216+ import tests.baz
217+ [file tests/__init__.py]
218+ [file tests/baz.py]
219+ 42 + "no" # type: ignore
220+
221+ [file mypy.ini]
222+ \[mypy]
223+ enable_error_code = ignore-without-code, truthy-bool
224+
225+ \[mypy-tests.*]
226+ disable_error_code = ignore-without-code
227+
228+ [case testInlineErrorCodesOverrideConfigSmall2]
229+ # flags: --config-file tmp/mypy.ini
230+ import tests.bar
231+ import tests.baz
232+ [file tests/__init__.py]
233+ [file tests/baz.py]
234+ 42 + "no" # type: ignore
235+ [file tests/bar.py]
236+ # mypy: enable-error-code="ignore-without-code"
237+
238+ def foo() -> int: ...
239+ if foo: ... # E: Function "foo" could always be true in boolean context
240+ 42 + "no" # type: ignore # E: "type: ignore" comment without error code (consider "type: ignore[operator]" instead)
241+
242+ [file mypy.ini]
243+ \[mypy]
244+ enable_error_code = ignore-without-code, truthy-bool
245+
246+ \[mypy-tests.*]
247+ disable_error_code = ignore-without-code
248+
249+
250+ [case testInlineErrorCodesOverrideConfigSmallBackward]
251+ # flags: --config-file tmp/mypy.ini
252+ import tests.bar
253+ import tests.baz
254+ [file tests/__init__.py]
255+ [file tests/baz.py]
256+ 42 + "no" # type: ignore # E: "type: ignore" comment without error code (consider "type: ignore[operator]" instead)
257+ [file tests/bar.py]
258+ # mypy: disable-error-code="ignore-without-code"
259+ 42 + "no" # type: ignore
260+
261+ [file mypy.ini]
262+ \[mypy]
263+ enable_error_code = ignore-without-code, truthy-bool
264+
265+ \[mypy-tests.*]
266+ enable_error_code = ignore-without-code
267+
268+ [case testInlineOverrideConfig]
269+ # flags: --config-file tmp/mypy.ini
270+ import foo
271+ import tests.bar
272+ import tests.baz
273+ [file foo.py]
274+ # mypy: disable-error-code="truthy-bool"
275+ class Foo:
276+ pass
277+
278+ foo = Foo()
279+ if foo: ...
280+ 42 # type: ignore # E: Unused "type: ignore" comment
281+
282+ [file tests/__init__.py]
283+ [file tests/bar.py]
284+ # mypy: warn_unused_ignores
285+
286+ def foo() -> int: ...
287+ if foo: ... # E: Function "foo" could always be true in boolean context
288+ 42 # type: ignore # E: Unused "type: ignore" comment
289+
290+ [file tests/baz.py]
291+ # mypy: disable-error-code="truthy-bool"
292+ class Foo:
293+ pass
294+
295+ foo = Foo()
296+ if foo: ...
297+ 42 # type: ignore
298+
299+ [file mypy.ini]
300+ \[mypy]
301+ warn_unused_ignores = True
302+
303+ \[mypy-tests.*]
304+ warn_unused_ignores = False
305+
306+
214307[case testIgnoreErrorsSimple]
215308# mypy: ignore-errors=True
216309
@@ -324,6 +417,61 @@ foo = Foo()
324417if foo: ...
32541842 + "no" # type: ignore
326419
327-
328420[case testInlinePythonVersion]
329421# mypy: python-version=3.10 # E: python_version not supported in inline configuration
422+
423+ [case testInlineErrorCodesArentRuinedByOthersBaseCase]
424+ # mypy: disable-error-code=name-defined
425+ a
426+
427+ [case testInlineErrorCodesArentRuinedByOthersInvalid]
428+ # mypy: disable-error-code=name-defined
429+ # mypy: AMONGUS
430+ a
431+ [out]
432+ main:2: error: Unrecognized option: amongus = True
433+
434+ [case testInlineErrorCodesArentRuinedByOthersInvalidBefore]
435+ # mypy: AMONGUS
436+ # mypy: disable-error-code=name-defined
437+ a
438+ [out]
439+ main:1: error: Unrecognized option: amongus = True
440+
441+ [case testInlineErrorCodesArentRuinedByOthersSe]
442+ # mypy: disable-error-code=name-defined
443+ # mypy: strict-equality
444+ def is_magic(x: bytes) -> bool:
445+ y
446+ return x == 'magic' # E: Unsupported left operand type for == ("bytes")
447+
448+ [case testInlineConfigErrorCodesOffAndOn]
449+ # mypy: disable-error-code=name-defined
450+ # mypy: enable-error-code=name-defined
451+ a # E: Name "a" is not defined
452+
453+ [case testInlineConfigErrorCodesOnAndOff]
454+ # mypy: enable-error-code=name-defined
455+ # mypy: disable-error-code=name-defined
456+ a # E: Name "a" is not defined
457+
458+ [case testConfigFileErrorCodesOnAndOff]
459+ # flags: --config-file tmp/mypy.ini
460+ import foo
461+ [file foo.py]
462+ 42 + "no" # type: ignore # E: "type: ignore" comment without error code (consider "type: ignore[operator]" instead)
463+ [file mypy.ini]
464+ \[mypy]
465+ enable_error_code = ignore-without-code
466+ disable_error_code = ignore-without-code
467+
468+ [case testInlineConfigBaseCaseWui]
469+ # mypy: warn_unused_ignores
470+ x = 1 # type: ignore # E: Unused "type: ignore" comment
471+
472+ [case testInlineConfigIsntRuinedByOthersInvalidWui]
473+ # mypy: warn_unused_ignores
474+ # mypy: AMONGUS
475+ x = 1 # type: ignore # E: Unused "type: ignore" comment
476+ [out]
477+ main:2: error: Unrecognized option: amongus = True
0 commit comments