From 8d74622631ca4471364ebf0509502f2ac25c0bb4 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Mon, 19 Jan 2026 13:30:23 +0100 Subject: [PATCH] Allow Mypy/Zuban to ignore specific error codes This was the proposal of what Rebecca proposed in https://discuss.python.org/t/allow-type-ignore-mypy-style-error-codes-in-conformance-tests/105433/5 --- conformance/results/mypy/directives_type_ignore.toml | 3 --- conformance/results/results.html | 6 +++--- conformance/results/zuban/classes_classvar.toml | 2 +- conformance/results/zuban/constructors_call_init.toml | 6 +++--- conformance/results/zuban/directives_type_ignore.toml | 11 +---------- conformance/results/zuban/generics_type_erasure.toml | 10 +--------- .../zuban/generics_typevartuple_specialization.toml | 4 ++-- conformance/results/zuban/tuples_unpacked.toml | 10 +++++----- conformance/results/zuban/version.toml | 2 +- conformance/tests/directives_type_ignore.py | 2 +- 10 files changed, 18 insertions(+), 38 deletions(-) diff --git a/conformance/results/mypy/directives_type_ignore.toml b/conformance/results/mypy/directives_type_ignore.toml index 8dfefb377..5ac164ed4 100644 --- a/conformance/results/mypy/directives_type_ignore.toml +++ b/conformance/results/mypy/directives_type_ignore.toml @@ -5,11 +5,8 @@ Does not honor "# type: ignore" comment if comment includes additional text. output = """ directives_type_ignore.py:11: error: Invalid "type: ignore" comment [syntax] directives_type_ignore.py:11: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] -directives_type_ignore.py:14: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] -directives_type_ignore.py:14: note: Error code "assignment" not covered by "type: ignore" comment """ conformance_automated = "Fail" errors_diff = """ Line 11: Unexpected errors ['directives_type_ignore.py:11: error: Invalid "type: ignore" comment [syntax]', 'directives_type_ignore.py:11: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment]'] -Line 14: Unexpected errors ['directives_type_ignore.py:14: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment]'] """ diff --git a/conformance/results/results.html b/conformance/results/results.html index cc9b4f3ec..d4fa9972a 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -162,7 +162,7 @@

Python Type System Conformance Test Results

pyright 1.1.407
-
zuban 0.4.1
+
zuban 0.4.2
pyrefly 0.46.1
@@ -353,7 +353,7 @@

Python Type System Conformance Test Results

     generics_type_erasure
Partial

Infers Node[Never] instead of Node[Any] when argument is not provided.

False negative on instance attribute access on type(node).

Pass -
Partial

Infers Node[Never] instead of Node[Any] when argument is not provided.

+Pass Pass      generics_typevartuple_args @@ -1031,7 +1031,7 @@

Python Type System Conformance Test Results

     directives_type_ignore
Partial

Does not honor "# type: ignore" comment if comment includes additional text.

Pass -
Partial

Does not honor "# type: ignore" comment if comment includes additional text.

+Pass Pass      directives_type_ignore_file1 diff --git a/conformance/results/zuban/classes_classvar.toml b/conformance/results/zuban/classes_classvar.toml index 47ee309f5..a451ac506 100644 --- a/conformance/results/zuban/classes_classvar.toml +++ b/conformance/results/zuban/classes_classvar.toml @@ -8,7 +8,7 @@ classes_classvar.py:40: error: Name "var" is not defined [name-defined] classes_classvar.py:45: error: ClassVar cannot contain type variables [misc] classes_classvar.py:46: error: ClassVar cannot contain type variables [misc] classes_classvar.py:47: error: ClassVar cannot contain type variables [misc] -classes_classvar.py:52: error: Incompatible types in assignment (expression has type "dict[Never, Never]", variable has type "list[str]") [assignment] +classes_classvar.py:52: error: Incompatible types in assignment (expression has type "dict[Any, Any]", variable has type "list[str]") [assignment] classes_classvar.py:54: error: Variable should not be annotated with both ClassVar and Final [misc] classes_classvar.py:55: error: Invalid Type: ClassVar nested inside other type [misc] classes_classvar.py:66: error: Type in ClassVar[...] can only be omitted if there is an initializer [misc] diff --git a/conformance/results/zuban/constructors_call_init.toml b/conformance/results/zuban/constructors_call_init.toml index a642bef3e..3ebf04786 100644 --- a/conformance/results/zuban/constructors_call_init.toml +++ b/conformance/results/zuban/constructors_call_init.toml @@ -3,9 +3,9 @@ errors_diff = """ """ output = """ constructors_call_init.py:21: error: Argument 1 to "Class1" has incompatible type "float"; expected "int" [arg-type] -constructors_call_init.py:42: error: Argument 1 to "Class3" has incompatible type "Class2[Never]"; expected "Self | None" [arg-type] +constructors_call_init.py:42: error: Argument 1 to "Class3" has incompatible type "Class2[Any]"; expected "Self | None" [arg-type] constructors_call_init.py:56: error: Invalid self type in __init__ [call-arg] -constructors_call_init.py:107: error: The type of self "T1" has type vars in non standard potisions for class "Class8" [misc] -constructors_call_init.py:107: error: The type of self "T2" has type vars in non standard potisions for class "Class8" [misc] +constructors_call_init.py:107: error: The type of self "T1" has type vars in non standard positions for class "Class8" [misc] +constructors_call_init.py:107: error: The type of self "T2" has type vars in non standard positions for class "Class8" [misc] constructors_call_init.py:130: error: Too many arguments for "Class11" [call-arg] """ diff --git a/conformance/results/zuban/directives_type_ignore.toml b/conformance/results/zuban/directives_type_ignore.toml index 7f7a32e76..cdd4d0cd9 100644 --- a/conformance/results/zuban/directives_type_ignore.toml +++ b/conformance/results/zuban/directives_type_ignore.toml @@ -1,14 +1,5 @@ -conformant = "Partial" -notes = """ -Does not honor "# type: ignore" comment if comment includes additional text. -""" -conformance_automated = "Fail" +conformance_automated = "Pass" errors_diff = """ -Line 11: Unexpected errors ['directives_type_ignore.py:11: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment]'] -Line 14: Unexpected errors ['directives_type_ignore.py:14: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment]'] """ output = """ -directives_type_ignore.py:11: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] -directives_type_ignore.py:14: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] -directives_type_ignore.py:14: note: Error code "assignment" not covered by "type: ignore" comment """ diff --git a/conformance/results/zuban/generics_type_erasure.toml b/conformance/results/zuban/generics_type_erasure.toml index ae8e9d615..764ba5bcb 100644 --- a/conformance/results/zuban/generics_type_erasure.toml +++ b/conformance/results/zuban/generics_type_erasure.toml @@ -1,15 +1,7 @@ -conformant = "Partial" -notes = """ -Infers Node[Never] instead of Node[Any] when argument is not provided. -""" -conformance_automated = "Fail" +conformance_automated = "Pass" errors_diff = """ -Line 19: Unexpected errors ['generics_type_erasure.py:19: error: Expression is of type "Node[Never]", not "Node[Any]" [misc]'] -Line 22: Unexpected errors ['generics_type_erasure.py:22: error: Expression is of type "Never", not "Any" [misc]'] """ output = """ -generics_type_erasure.py:19: error: Expression is of type "Node[Never]", not "Node[Any]" [misc] -generics_type_erasure.py:22: error: Expression is of type "Never", not "Any" [misc] generics_type_erasure.py:38: error: Argument 1 to "Node" has incompatible type "str"; expected "int | None" [arg-type] generics_type_erasure.py:40: error: Argument 1 to "Node" has incompatible type "int"; expected "str | None" [arg-type] generics_type_erasure.py:42: error: Access to generic instance variables via class is ambiguous [misc] diff --git a/conformance/results/zuban/generics_typevartuple_specialization.toml b/conformance/results/zuban/generics_typevartuple_specialization.toml index e7148e564..b7b6182df 100644 --- a/conformance/results/zuban/generics_typevartuple_specialization.toml +++ b/conformance/results/zuban/generics_typevartuple_specialization.toml @@ -5,8 +5,8 @@ output = """ generics_typevartuple_specialization.py:109: error: Unpack is only valid in a variadic position [misc] generics_typevartuple_specialization.py:109: error: TypeVarTuple "Ts" is unbound [misc] generics_typevartuple_specialization.py:110: error: Unpack is only valid in a variadic position [misc] -generics_typevartuple_specialization.py:121: error: More than one Unpack in a type is not allowed [misc] -generics_typevartuple_specialization.py:122: error: More than one Unpack in a type is not allowed [misc] +generics_typevartuple_specialization.py:121: error: More than one variadic Unpack in a type is not allowed [misc] +generics_typevartuple_specialization.py:122: error: More than one variadic Unpack in a type is not allowed [misc] generics_typevartuple_specialization.py:127: error: Bad number of arguments for type alias, expected at least 2, given 2 [misc] generics_typevartuple_specialization.py:163: error: TypeVarTuple cannot be split [misc] """ diff --git a/conformance/results/zuban/tuples_unpacked.toml b/conformance/results/zuban/tuples_unpacked.toml index ab51bf6da..f550fe371 100644 --- a/conformance/results/zuban/tuples_unpacked.toml +++ b/conformance/results/zuban/tuples_unpacked.toml @@ -2,9 +2,9 @@ conformance_automated = "Pass" errors_diff = """ """ output = """ -tuples_unpacked.py:40: error: More than one Unpack in a type is not allowed [misc] -tuples_unpacked.py:41: error: More than one Unpack in a type is not allowed [misc] -tuples_unpacked.py:51: error: More than one Unpack in a type is not allowed [misc] -tuples_unpacked.py:59: error: More than one Unpack in a type is not allowed [misc] -tuples_unpacked.py:61: error: More than one Unpack in a type is not allowed [misc] +tuples_unpacked.py:40: error: More than one variadic Unpack in a type is not allowed [misc] +tuples_unpacked.py:41: error: More than one variadic Unpack in a type is not allowed [misc] +tuples_unpacked.py:51: error: More than one variadic Unpack in a type is not allowed [misc] +tuples_unpacked.py:59: error: More than one variadic Unpack in a type is not allowed [misc] +tuples_unpacked.py:61: error: More than one variadic Unpack in a type is not allowed [misc] """ diff --git a/conformance/results/zuban/version.toml b/conformance/results/zuban/version.toml index b9b7c1b8d..38806c06e 100644 --- a/conformance/results/zuban/version.toml +++ b/conformance/results/zuban/version.toml @@ -1 +1 @@ -version = "zuban 0.4.1" +version = "zuban 0.4.2" diff --git a/conformance/tests/directives_type_ignore.py b/conformance/tests/directives_type_ignore.py index b96d23aea..f76802b94 100644 --- a/conformance/tests/directives_type_ignore.py +++ b/conformance/tests/directives_type_ignore.py @@ -11,7 +11,7 @@ y: int = "" # type: ignore - additional stuff # The following type violation should be suppressed. -z: int = "" # type: ignore[additional_stuff] +z: int = "" # type: ignore[assignment] # > In some cases, linting tools or other comments may be needed on the same # > line as a type comment. In these cases, the type comment should be before