From 75caed75a5f930c674360a5559788bad1b306bd8 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Sat, 20 Jul 2024 11:45:36 -0700 Subject: [PATCH] =?UTF-8?q?Added=20conformance=20checking=20for=20the=20"c?= =?UTF-8?q?onverter"=20field=20specifier=20parame=E2=80=A6=20(#1813)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added conformance checking for the "converter" field specifier parameter in dataclass_transform. None of the type checkers support it currently. --- .../mypy/dataclasses_transform_converter.toml | 48 +++++++ .../pyre/dataclasses_transform_converter.toml | 48 +++++++ conformance/results/pyre/version.toml | 2 +- .../dataclasses_transform_converter.toml | 77 ++++++++++ conformance/results/pyright/version.toml | 2 +- .../dataclasses_transform_converter.toml | 30 ++++ conformance/results/pytype/version.toml | 2 +- conformance/results/results.html | 12 +- .../tests/dataclasses_transform_converter.py | 132 ++++++++++++++++++ 9 files changed, 347 insertions(+), 6 deletions(-) create mode 100644 conformance/results/mypy/dataclasses_transform_converter.toml create mode 100644 conformance/results/pyre/dataclasses_transform_converter.toml create mode 100644 conformance/results/pyright/dataclasses_transform_converter.toml create mode 100644 conformance/results/pytype/dataclasses_transform_converter.toml create mode 100644 conformance/tests/dataclasses_transform_converter.py diff --git a/conformance/results/mypy/dataclasses_transform_converter.toml b/conformance/results/mypy/dataclasses_transform_converter.toml new file mode 100644 index 00000000..483d0202 --- /dev/null +++ b/conformance/results/mypy/dataclasses_transform_converter.toml @@ -0,0 +1,48 @@ +conformant = "Unsupported" +notes = """ +Converter parameter not yet supported. +""" +conformance_automated = "Fail" +errors_diff = """ +Line 47: Expected 1 errors +Line 48: Expected 1 errors +Line 117: Expected 1 errors +Line 129: Expected 1 errors +Line 132: Expected 1 errors +Line 111: Unexpected errors ['dataclasses_transform_converter.py:111: error: Argument 1 to "DC2" has incompatible type "str"; expected "int" [arg-type]', 'dataclasses_transform_converter.py:111: error: Argument 2 to "DC2" has incompatible type "str"; expected "int" [arg-type]', 'dataclasses_transform_converter.py:111: error: Argument 3 to "DC2" has incompatible type "str"; expected "int" [arg-type]', 'dataclasses_transform_converter.py:111: error: Argument 4 to "DC2" has incompatible type "bytes"; expected "ConverterClass" [arg-type]', 'dataclasses_transform_converter.py:111: error: Argument 5 to "DC2" has incompatible type "list[Never]"; expected "int" [arg-type]'] +Line 113: Unexpected errors ['dataclasses_transform_converter.py:113: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment]'] +Line 114: Unexpected errors ['dataclasses_transform_converter.py:114: error: Incompatible types in assignment (expression has type "str", variable has type "ConverterClass") [assignment]'] +Line 115: Unexpected errors ['dataclasses_transform_converter.py:115: error: Incompatible types in assignment (expression has type "bytes", variable has type "ConverterClass") [assignment]'] +Line 120: Unexpected errors ['dataclasses_transform_converter.py:120: error: Argument 1 to "DC2" has incompatible type "str"; expected "int" [arg-type]', 'dataclasses_transform_converter.py:120: error: Argument 2 to "DC2" has incompatible type "str"; expected "int" [arg-type]', 'dataclasses_transform_converter.py:120: error: Argument 3 to "DC2" has incompatible type "str"; expected "int" [arg-type]', 'dataclasses_transform_converter.py:120: error: Argument 4 to "DC2" has incompatible type "str"; expected "ConverterClass" [arg-type]', 'dataclasses_transform_converter.py:120: error: Argument 5 to "DC2" has incompatible type "str"; expected "int" [arg-type]', 'dataclasses_transform_converter.py:120: error: Argument 6 to "DC2" has incompatible type "tuple[tuple[str, str], tuple[str, str]]"; expected "dict[str, str]" [arg-type]'] +""" +output = """ +dataclasses_transform_converter.py:106: error: Argument 2 to "DC2" has incompatible type "str"; expected "int" [arg-type] +dataclasses_transform_converter.py:106: error: Argument 3 to "DC2" has incompatible type "str"; expected "int" [arg-type] +dataclasses_transform_converter.py:106: error: Argument 4 to "DC2" has incompatible type "bytes"; expected "ConverterClass" [arg-type] +dataclasses_transform_converter.py:106: error: Argument 5 to "DC2" has incompatible type "list[Never]"; expected "int" [arg-type] +dataclasses_transform_converter.py:107: error: Argument 1 to "DC2" has incompatible type "str"; expected "int" [arg-type] +dataclasses_transform_converter.py:107: error: Argument 2 to "DC2" has incompatible type "str"; expected "int" [arg-type] +dataclasses_transform_converter.py:107: error: Argument 3 to "DC2" has incompatible type "str"; expected "int" [arg-type] +dataclasses_transform_converter.py:107: error: Argument 4 to "DC2" has incompatible type "int"; expected "ConverterClass" [arg-type] +dataclasses_transform_converter.py:107: error: Argument 5 to "DC2" has incompatible type "list[Never]"; expected "int" [arg-type] +dataclasses_transform_converter.py:108: error: Argument 1 to "DC2" has incompatible type "str"; expected "int" [arg-type] +dataclasses_transform_converter.py:108: error: Argument 2 to "DC2" has incompatible type "str"; expected "int" [arg-type] +dataclasses_transform_converter.py:108: error: Argument 3 to "DC2" has incompatible type "str"; expected "int" [arg-type] +dataclasses_transform_converter.py:108: error: Argument 4 to "DC2" has incompatible type "str"; expected "ConverterClass" [arg-type] +dataclasses_transform_converter.py:108: error: Argument 5 to "DC2" has incompatible type "complex"; expected "int" [arg-type] +dataclasses_transform_converter.py:111: error: Argument 1 to "DC2" has incompatible type "str"; expected "int" [arg-type] +dataclasses_transform_converter.py:111: error: Argument 2 to "DC2" has incompatible type "str"; expected "int" [arg-type] +dataclasses_transform_converter.py:111: error: Argument 3 to "DC2" has incompatible type "str"; expected "int" [arg-type] +dataclasses_transform_converter.py:111: error: Argument 4 to "DC2" has incompatible type "bytes"; expected "ConverterClass" [arg-type] +dataclasses_transform_converter.py:111: error: Argument 5 to "DC2" has incompatible type "list[Never]"; expected "int" [arg-type] +dataclasses_transform_converter.py:113: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] +dataclasses_transform_converter.py:114: error: Incompatible types in assignment (expression has type "str", variable has type "ConverterClass") [assignment] +dataclasses_transform_converter.py:115: error: Incompatible types in assignment (expression has type "bytes", variable has type "ConverterClass") [assignment] +dataclasses_transform_converter.py:118: error: Incompatible types in assignment (expression has type "int", variable has type "ConverterClass") [assignment] +dataclasses_transform_converter.py:120: error: Argument 1 to "DC2" has incompatible type "str"; expected "int" [arg-type] +dataclasses_transform_converter.py:120: error: Argument 2 to "DC2" has incompatible type "str"; expected "int" [arg-type] +dataclasses_transform_converter.py:120: error: Argument 3 to "DC2" has incompatible type "str"; expected "int" [arg-type] +dataclasses_transform_converter.py:120: error: Argument 4 to "DC2" has incompatible type "str"; expected "ConverterClass" [arg-type] +dataclasses_transform_converter.py:120: error: Argument 5 to "DC2" has incompatible type "str"; expected "int" [arg-type] +dataclasses_transform_converter.py:120: error: Argument 6 to "DC2" has incompatible type "tuple[tuple[str, str], tuple[str, str]]"; expected "dict[str, str]" [arg-type] +""" diff --git a/conformance/results/pyre/dataclasses_transform_converter.toml b/conformance/results/pyre/dataclasses_transform_converter.toml new file mode 100644 index 00000000..20db71dd --- /dev/null +++ b/conformance/results/pyre/dataclasses_transform_converter.toml @@ -0,0 +1,48 @@ +conformant = "Unsupported" +notes = """ +Converter parameter not yet supported. +""" +conformance_automated = "Fail" +errors_diff = """ +Line 47: Expected 1 errors +Line 48: Expected 1 errors +Line 117: Expected 1 errors +Line 129: Expected 1 errors +Line 132: Expected 1 errors +Line 111: Unexpected errors ['dataclasses_transform_converter.py:111:10 Incompatible parameter type [6]: In call `DC2.__init__`, for 1st positional argument, expected `int` but got `str`.', 'dataclasses_transform_converter.py:111:16 Incompatible parameter type [6]: In call `DC2.__init__`, for 2nd positional argument, expected `int` but got `str`.', 'dataclasses_transform_converter.py:111:22 Incompatible parameter type [6]: In call `DC2.__init__`, for 3rd positional argument, expected `int` but got `str`.', 'dataclasses_transform_converter.py:111:28 Incompatible parameter type [6]: In call `DC2.__init__`, for 4th positional argument, expected `ConverterClass` but got `bytes`.', 'dataclasses_transform_converter.py:111:35 Incompatible parameter type [6]: In call `DC2.__init__`, for 5th positional argument, expected `int` but got `List[Variable[_T]]`.'] +Line 113: Unexpected errors ['dataclasses_transform_converter.py:113:0 Incompatible attribute type [8]: Attribute `field0` declared in class `DC2` has type `int` but is used as type `str`.'] +Line 114: Unexpected errors ['dataclasses_transform_converter.py:114:0 Incompatible attribute type [8]: Attribute `field3` declared in class `DC2` has type `ConverterClass` but is used as type `str`.'] +Line 115: Unexpected errors ['dataclasses_transform_converter.py:115:0 Incompatible attribute type [8]: Attribute `field3` declared in class `DC2` has type `ConverterClass` but is used as type `bytes`.'] +Line 120: Unexpected errors ['dataclasses_transform_converter.py:120:10 Incompatible parameter type [6]: In call `DC2.__init__`, for 1st positional argument, expected `int` but got `str`.', 'dataclasses_transform_converter.py:120:16 Incompatible parameter type [6]: In call `DC2.__init__`, for 2nd positional argument, expected `int` but got `str`.', 'dataclasses_transform_converter.py:120:22 Incompatible parameter type [6]: In call `DC2.__init__`, for 3rd positional argument, expected `int` but got `str`.', 'dataclasses_transform_converter.py:120:28 Incompatible parameter type [6]: In call `DC2.__init__`, for 4th positional argument, expected `ConverterClass` but got `str`.', 'dataclasses_transform_converter.py:120:34 Incompatible parameter type [6]: In call `DC2.__init__`, for 5th positional argument, expected `int` but got `str`.', 'dataclasses_transform_converter.py:120:39 Incompatible parameter type [6]: In call `DC2.__init__`, for 6th positional argument, expected `Dict[str, str]` but got `Tuple[Tuple[str, str], Tuple[str, str]]`.'] +""" +output = """ +dataclasses_transform_converter.py:106:7 Incompatible parameter type [6]: In call `DC2.__init__`, for 2nd positional argument, expected `int` but got `str`. +dataclasses_transform_converter.py:106:13 Incompatible parameter type [6]: In call `DC2.__init__`, for 3rd positional argument, expected `int` but got `str`. +dataclasses_transform_converter.py:106:19 Incompatible parameter type [6]: In call `DC2.__init__`, for 4th positional argument, expected `ConverterClass` but got `bytes`. +dataclasses_transform_converter.py:106:26 Incompatible parameter type [6]: In call `DC2.__init__`, for 5th positional argument, expected `int` but got `List[Variable[_T]]`. +dataclasses_transform_converter.py:107:4 Incompatible parameter type [6]: In call `DC2.__init__`, for 1st positional argument, expected `int` but got `str`. +dataclasses_transform_converter.py:107:10 Incompatible parameter type [6]: In call `DC2.__init__`, for 2nd positional argument, expected `int` but got `str`. +dataclasses_transform_converter.py:107:16 Incompatible parameter type [6]: In call `DC2.__init__`, for 3rd positional argument, expected `int` but got `str`. +dataclasses_transform_converter.py:107:22 Incompatible parameter type [6]: In call `DC2.__init__`, for 4th positional argument, expected `ConverterClass` but got `int`. +dataclasses_transform_converter.py:107:25 Incompatible parameter type [6]: In call `DC2.__init__`, for 5th positional argument, expected `int` but got `List[Variable[_T]]`. +dataclasses_transform_converter.py:108:4 Incompatible parameter type [6]: In call `DC2.__init__`, for 1st positional argument, expected `int` but got `str`. +dataclasses_transform_converter.py:108:10 Incompatible parameter type [6]: In call `DC2.__init__`, for 2nd positional argument, expected `int` but got `str`. +dataclasses_transform_converter.py:108:16 Incompatible parameter type [6]: In call `DC2.__init__`, for 3rd positional argument, expected `int` but got `str`. +dataclasses_transform_converter.py:108:22 Incompatible parameter type [6]: In call `DC2.__init__`, for 4th positional argument, expected `ConverterClass` but got `str`. +dataclasses_transform_converter.py:108:28 Incompatible parameter type [6]: In call `DC2.__init__`, for 5th positional argument, expected `int` but got `complex`. +dataclasses_transform_converter.py:111:10 Incompatible parameter type [6]: In call `DC2.__init__`, for 1st positional argument, expected `int` but got `str`. +dataclasses_transform_converter.py:111:16 Incompatible parameter type [6]: In call `DC2.__init__`, for 2nd positional argument, expected `int` but got `str`. +dataclasses_transform_converter.py:111:22 Incompatible parameter type [6]: In call `DC2.__init__`, for 3rd positional argument, expected `int` but got `str`. +dataclasses_transform_converter.py:111:28 Incompatible parameter type [6]: In call `DC2.__init__`, for 4th positional argument, expected `ConverterClass` but got `bytes`. +dataclasses_transform_converter.py:111:35 Incompatible parameter type [6]: In call `DC2.__init__`, for 5th positional argument, expected `int` but got `List[Variable[_T]]`. +dataclasses_transform_converter.py:113:0 Incompatible attribute type [8]: Attribute `field0` declared in class `DC2` has type `int` but is used as type `str`. +dataclasses_transform_converter.py:114:0 Incompatible attribute type [8]: Attribute `field3` declared in class `DC2` has type `ConverterClass` but is used as type `str`. +dataclasses_transform_converter.py:115:0 Incompatible attribute type [8]: Attribute `field3` declared in class `DC2` has type `ConverterClass` but is used as type `bytes`. +dataclasses_transform_converter.py:118:0 Incompatible attribute type [8]: Attribute `field3` declared in class `DC2` has type `ConverterClass` but is used as type `int`. +dataclasses_transform_converter.py:120:10 Incompatible parameter type [6]: In call `DC2.__init__`, for 1st positional argument, expected `int` but got `str`. +dataclasses_transform_converter.py:120:16 Incompatible parameter type [6]: In call `DC2.__init__`, for 2nd positional argument, expected `int` but got `str`. +dataclasses_transform_converter.py:120:22 Incompatible parameter type [6]: In call `DC2.__init__`, for 3rd positional argument, expected `int` but got `str`. +dataclasses_transform_converter.py:120:28 Incompatible parameter type [6]: In call `DC2.__init__`, for 4th positional argument, expected `ConverterClass` but got `str`. +dataclasses_transform_converter.py:120:34 Incompatible parameter type [6]: In call `DC2.__init__`, for 5th positional argument, expected `int` but got `str`. +dataclasses_transform_converter.py:120:39 Incompatible parameter type [6]: In call `DC2.__init__`, for 6th positional argument, expected `Dict[str, str]` but got `Tuple[Tuple[str, str], Tuple[str, str]]`. +""" diff --git a/conformance/results/pyre/version.toml b/conformance/results/pyre/version.toml index fff2c3f2..98d9d6eb 100644 --- a/conformance/results/pyre/version.toml +++ b/conformance/results/pyre/version.toml @@ -1,2 +1,2 @@ version = "pyre 0.9.22" -test_duration = 2.8 +test_duration = 3.4 diff --git a/conformance/results/pyright/dataclasses_transform_converter.toml b/conformance/results/pyright/dataclasses_transform_converter.toml new file mode 100644 index 00000000..9f1780b3 --- /dev/null +++ b/conformance/results/pyright/dataclasses_transform_converter.toml @@ -0,0 +1,77 @@ +conformant = "Unsupported" +notes = """ +Converter parameter not yet supported. +""" +conformance_automated = "Fail" +errors_diff = """ +Line 47: Expected 1 errors +Line 48: Expected 1 errors +Line 117: Expected 1 errors +Line 129: Expected 1 errors +Line 132: Expected 1 errors +Line 111: Unexpected errors ['dataclasses_transform_converter.py:111:11 - error: Argument of type "Literal[\\'f0\\']" cannot be assigned to parameter "field0" of type "int" in function "__init__"', 'dataclasses_transform_converter.py:111:17 - error: Argument of type "Literal[\\'f1\\']" cannot be assigned to parameter "field1" of type "int" in function "__init__"', 'dataclasses_transform_converter.py:111:23 - error: Argument of type "Literal[\\'f2\\']" cannot be assigned to parameter "field2" of type "int" in function "__init__"', 'dataclasses_transform_converter.py:111:29 - error: Argument of type "Literal[b"f6"]" cannot be assigned to parameter "field3" of type "ConverterClass" in function "__init__"', 'dataclasses_transform_converter.py:111:36 - error: Argument of type "list[Any]" cannot be assigned to parameter "field4" of type "int" in function "__init__"'] +Line 113: Unexpected errors ['dataclasses_transform_converter.py:113:14 - error: Cannot assign to attribute "field0" for class "DC2"'] +Line 114: Unexpected errors ['dataclasses_transform_converter.py:114:14 - error: Cannot assign to attribute "field3" for class "DC2"'] +Line 115: Unexpected errors ['dataclasses_transform_converter.py:115:14 - error: Cannot assign to attribute "field3" for class "DC2"'] +Line 120: Unexpected errors ['dataclasses_transform_converter.py:120:11 - error: Argument of type "Literal[\\'f0\\']" cannot be assigned to parameter "field0" of type "int" in function "__init__"', 'dataclasses_transform_converter.py:120:17 - error: Argument of type "Literal[\\'f1\\']" cannot be assigned to parameter "field1" of type "int" in function "__init__"', 'dataclasses_transform_converter.py:120:23 - error: Argument of type "Literal[\\'f2\\']" cannot be assigned to parameter "field2" of type "int" in function "__init__"', 'dataclasses_transform_converter.py:120:29 - error: Argument of type "Literal[\\'f6\\']" cannot be assigned to parameter "field3" of type "ConverterClass" in function "__init__"', 'dataclasses_transform_converter.py:120:35 - error: Argument of type "Literal[\\'1\\']" cannot be assigned to parameter "field4" of type "int" in function "__init__"', 'dataclasses_transform_converter.py:120:40 - error: Argument of type "tuple[tuple[str, str], tuple[str, str]]" cannot be assigned to parameter "field5" of type "dict[str, str]" in function "__init__"'] +""" +output = """ +dataclasses_transform_converter.py:106:8 - error: Argument of type "Literal['f1']" cannot be assigned to parameter "field1" of type "int" in function "__init__" +  "Literal['f1']" is incompatible with "int" (reportArgumentType) +dataclasses_transform_converter.py:106:14 - error: Argument of type "Literal['f2']" cannot be assigned to parameter "field2" of type "int" in function "__init__" +  "Literal['f2']" is incompatible with "int" (reportArgumentType) +dataclasses_transform_converter.py:106:20 - error: Argument of type "Literal[b"f3"]" cannot be assigned to parameter "field3" of type "ConverterClass" in function "__init__" +  "Literal[b"f3"]" is incompatible with "ConverterClass" (reportArgumentType) +dataclasses_transform_converter.py:106:27 - error: Argument of type "list[Any]" cannot be assigned to parameter "field4" of type "int" in function "__init__" +  "list[Any]" is incompatible with "int" (reportArgumentType) +dataclasses_transform_converter.py:107:5 - error: Argument of type "Literal['f0']" cannot be assigned to parameter "field0" of type "int" in function "__init__" +  "Literal['f0']" is incompatible with "int" (reportArgumentType) +dataclasses_transform_converter.py:107:11 - error: Argument of type "Literal['f1']" cannot be assigned to parameter "field1" of type "int" in function "__init__" +  "Literal['f1']" is incompatible with "int" (reportArgumentType) +dataclasses_transform_converter.py:107:17 - error: Argument of type "Literal['f2']" cannot be assigned to parameter "field2" of type "int" in function "__init__" +  "Literal['f2']" is incompatible with "int" (reportArgumentType) +dataclasses_transform_converter.py:107:23 - error: Argument of type "Literal[1]" cannot be assigned to parameter "field3" of type "ConverterClass" in function "__init__" +  "Literal[1]" is incompatible with "ConverterClass" (reportArgumentType) +dataclasses_transform_converter.py:107:26 - error: Argument of type "list[Any]" cannot be assigned to parameter "field4" of type "int" in function "__init__" +  "list[Any]" is incompatible with "int" (reportArgumentType) +dataclasses_transform_converter.py:108:5 - error: Argument of type "Literal['f0']" cannot be assigned to parameter "field0" of type "int" in function "__init__" +  "Literal['f0']" is incompatible with "int" (reportArgumentType) +dataclasses_transform_converter.py:108:11 - error: Argument of type "Literal['f1']" cannot be assigned to parameter "field1" of type "int" in function "__init__" +  "Literal['f1']" is incompatible with "int" (reportArgumentType) +dataclasses_transform_converter.py:108:17 - error: Argument of type "Literal['f2']" cannot be assigned to parameter "field2" of type "int" in function "__init__" +  "Literal['f2']" is incompatible with "int" (reportArgumentType) +dataclasses_transform_converter.py:108:23 - error: Argument of type "Literal['f3']" cannot be assigned to parameter "field3" of type "ConverterClass" in function "__init__" +  "Literal['f3']" is incompatible with "ConverterClass" (reportArgumentType) +dataclasses_transform_converter.py:108:29 - error: Argument of type "complex" cannot be assigned to parameter "field4" of type "int" in function "__init__" +  "complex" is incompatible with "int" (reportArgumentType) +dataclasses_transform_converter.py:111:11 - error: Argument of type "Literal['f0']" cannot be assigned to parameter "field0" of type "int" in function "__init__" +  "Literal['f0']" is incompatible with "int" (reportArgumentType) +dataclasses_transform_converter.py:111:17 - error: Argument of type "Literal['f1']" cannot be assigned to parameter "field1" of type "int" in function "__init__" +  "Literal['f1']" is incompatible with "int" (reportArgumentType) +dataclasses_transform_converter.py:111:23 - error: Argument of type "Literal['f2']" cannot be assigned to parameter "field2" of type "int" in function "__init__" +  "Literal['f2']" is incompatible with "int" (reportArgumentType) +dataclasses_transform_converter.py:111:29 - error: Argument of type "Literal[b"f6"]" cannot be assigned to parameter "field3" of type "ConverterClass" in function "__init__" +  "Literal[b"f6"]" is incompatible with "ConverterClass" (reportArgumentType) +dataclasses_transform_converter.py:111:36 - error: Argument of type "list[Any]" cannot be assigned to parameter "field4" of type "int" in function "__init__" +  "list[Any]" is incompatible with "int" (reportArgumentType) +dataclasses_transform_converter.py:113:14 - error: Cannot assign to attribute "field0" for class "DC2" +  "Literal['f1']" is incompatible with "int" (reportAttributeAccessIssue) +dataclasses_transform_converter.py:114:14 - error: Cannot assign to attribute "field3" for class "DC2" +  "Literal['f6']" is incompatible with "ConverterClass" (reportAttributeAccessIssue) +dataclasses_transform_converter.py:115:14 - error: Cannot assign to attribute "field3" for class "DC2" +  "Literal[b"f6"]" is incompatible with "ConverterClass" (reportAttributeAccessIssue) +dataclasses_transform_converter.py:118:14 - error: Cannot assign to attribute "field3" for class "DC2" +  "Literal[1]" is incompatible with "ConverterClass" (reportAttributeAccessIssue) +dataclasses_transform_converter.py:120:11 - error: Argument of type "Literal['f0']" cannot be assigned to parameter "field0" of type "int" in function "__init__" +  "Literal['f0']" is incompatible with "int" (reportArgumentType) +dataclasses_transform_converter.py:120:17 - error: Argument of type "Literal['f1']" cannot be assigned to parameter "field1" of type "int" in function "__init__" +  "Literal['f1']" is incompatible with "int" (reportArgumentType) +dataclasses_transform_converter.py:120:23 - error: Argument of type "Literal['f2']" cannot be assigned to parameter "field2" of type "int" in function "__init__" +  "Literal['f2']" is incompatible with "int" (reportArgumentType) +dataclasses_transform_converter.py:120:29 - error: Argument of type "Literal['f6']" cannot be assigned to parameter "field3" of type "ConverterClass" in function "__init__" +  "Literal['f6']" is incompatible with "ConverterClass" (reportArgumentType) +dataclasses_transform_converter.py:120:35 - error: Argument of type "Literal['1']" cannot be assigned to parameter "field4" of type "int" in function "__init__" +  "Literal['1']" is incompatible with "int" (reportArgumentType) +dataclasses_transform_converter.py:120:40 - error: Argument of type "tuple[tuple[str, str], tuple[str, str]]" cannot be assigned to parameter "field5" of type "dict[str, str]" in function "__init__" +  "tuple[tuple[str, str], tuple[str, str]]" is incompatible with "dict[str, str]" (reportArgumentType) +""" diff --git a/conformance/results/pyright/version.toml b/conformance/results/pyright/version.toml index 56d968ad..81d11bfb 100644 --- a/conformance/results/pyright/version.toml +++ b/conformance/results/pyright/version.toml @@ -1,2 +1,2 @@ version = "pyright 1.1.372" -test_duration = 1.4 +test_duration = 1.5 diff --git a/conformance/results/pytype/dataclasses_transform_converter.toml b/conformance/results/pytype/dataclasses_transform_converter.toml new file mode 100644 index 00000000..03fa070c --- /dev/null +++ b/conformance/results/pytype/dataclasses_transform_converter.toml @@ -0,0 +1,30 @@ +conformant = "Unsupported" +notes = """ +Converter parameter not yet supported. +""" +conformance_automated = "Fail" +errors_diff = """ +Line 47: Expected 1 errors +Line 48: Expected 1 errors +Line 117: Expected 1 errors +Line 129: Expected 1 errors +Line 132: Expected 1 errors +Line 28: Unexpected errors ['File "dataclasses_transform_converter.py", line 28, in : Arguments to dataclass_transform not supported yet [not-supported-yet]'] +Line 111: Unexpected errors ['File "dataclasses_transform_converter.py", line 111, in : Function DC2.__init__ was called with the wrong arguments [wrong-arg-types]'] +Line 113: Unexpected errors ['File "dataclasses_transform_converter.py", line 113, in : Type annotation for field0 does not match type of assignment [annotation-type-mismatch]'] +Line 114: Unexpected errors ['File "dataclasses_transform_converter.py", line 114, in : Type annotation for field3 does not match type of assignment [annotation-type-mismatch]'] +Line 115: Unexpected errors ['File "dataclasses_transform_converter.py", line 115, in : Type annotation for field3 does not match type of assignment [annotation-type-mismatch]'] +Line 120: Unexpected errors ['File "dataclasses_transform_converter.py", line 120, in : Function DC2.__init__ was called with the wrong arguments [wrong-arg-types]'] +""" +output = """ +File "dataclasses_transform_converter.py", line 28, in : Arguments to dataclass_transform not supported yet [not-supported-yet] +File "dataclasses_transform_converter.py", line 106, in : Function DC2.__init__ was called with the wrong arguments [wrong-arg-types] +File "dataclasses_transform_converter.py", line 107, in : Function DC2.__init__ was called with the wrong arguments [wrong-arg-types] +File "dataclasses_transform_converter.py", line 108, in : Function DC2.__init__ was called with the wrong arguments [wrong-arg-types] +File "dataclasses_transform_converter.py", line 111, in : Function DC2.__init__ was called with the wrong arguments [wrong-arg-types] +File "dataclasses_transform_converter.py", line 113, in : Type annotation for field0 does not match type of assignment [annotation-type-mismatch] +File "dataclasses_transform_converter.py", line 114, in : Type annotation for field3 does not match type of assignment [annotation-type-mismatch] +File "dataclasses_transform_converter.py", line 115, in : Type annotation for field3 does not match type of assignment [annotation-type-mismatch] +File "dataclasses_transform_converter.py", line 118, in : Type annotation for field3 does not match type of assignment [annotation-type-mismatch] +File "dataclasses_transform_converter.py", line 120, in : Function DC2.__init__ was called with the wrong arguments [wrong-arg-types] +""" diff --git a/conformance/results/pytype/version.toml b/conformance/results/pytype/version.toml index f00d1eab..8fb93c62 100644 --- a/conformance/results/pytype/version.toml +++ b/conformance/results/pytype/version.toml @@ -1,2 +1,2 @@ version = "pytype 2024.04.11" -test_duration = 30.9 +test_duration = 36.3 diff --git a/conformance/results/results.html b/conformance/results/results.html index b9b1894a..174a9c84 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -162,13 +162,13 @@

Python Type System Conformance Test Results

1.5sec
pyright 1.1.372
-
1.4sec
+
1.5sec
pyre 0.9.22
-
2.8sec
+
3.4sec
pytype 2024.04.11
-
30.9sec
+
36.3sec
@@ -744,6 +744,12 @@

Python Type System Conformance Test Results

Partial

Does not support field specifiers.

Emits "attribute not initialized" error for dataclass field.

Unsupported

Does not understand @dataclass_transform.

+     dataclasses_transform_converter +
Unsupported

Converter parameter not yet supported.

+
Unsupported

Converter parameter not yet supported.

+
Unsupported

Converter parameter not yet supported.

+
Unsupported

Converter parameter not yet supported.

+      dataclasses_transform_field
Partial

Does not properly handle field constructor that has default value for `kw_only` or `init` parameter.

Pass diff --git a/conformance/tests/dataclasses_transform_converter.py b/conformance/tests/dataclasses_transform_converter.py new file mode 100644 index 00000000..19602c18 --- /dev/null +++ b/conformance/tests/dataclasses_transform_converter.py @@ -0,0 +1,132 @@ +""" +Tests the dataclass_transform mechanism supports the "converter" parameter +in a field specifier class. +""" + +# Specification: https://typing.readthedocs.io/en/latest/spec/dataclasses.html#converters + +from typing import ( + Any, + Callable, + TypeVar, + dataclass_transform, + overload, +) + +T = TypeVar("T") + + +def model_field( + *, + converter: Callable[..., Any], + default: object = None, + default_factory: Callable[..., object] | None = None, +) -> Any: + ... + + +@dataclass_transform(field_specifiers=(model_field,)) +class ModelBase: + ... + + +# > The converter must be a callable that must accept a single positional +# > argument (but may accept other optional arguments, which are ignored for +# > typing purposes). + + +def bad_converter1() -> int: + return 0 + + +def bad_converter2(*, x: int) -> int: + return 0 + + +class DC1(ModelBase): + field1: int = model_field(converter=bad_converter1) # E + field2: int = model_field(converter=bad_converter2) # E + + +# > The type of the first positional parameter provides the type of the +# > synthesized __init__ parameter for the field. + +# > The return type of the callable must be assignable to the field’s +# > declared type. + + +def converter_simple(s: str) -> int: + return int(s) + + +def converter_with_param_before_args(s: str, *args: int, **kwargs: int) -> int: + return int(s) + + +def converter_with_args(*args: str) -> int: + return int(args[0]) + + +@overload +def overloaded_converter(s: str) -> int: + ... + + +@overload +def overloaded_converter(s: list[str]) -> int: + ... + + +def overloaded_converter(s: str | list[str], *args: str) -> int | str: + return 0 + + +class ConverterClass: + @overload + def __init__(self, val: str) -> None: + ... + + @overload + def __init__(self, val: bytes) -> None: + ... + + def __init__(self, val: str | bytes) -> None: + pass + + +class DC2(ModelBase): + field0: int = model_field(converter=converter_simple) + field1: int = model_field(converter=converter_with_param_before_args) + field2: int = model_field(converter=converter_with_args) + field3: ConverterClass = model_field(converter=ConverterClass) + field4: int = model_field(converter=overloaded_converter) + field5: dict[str, str] = model_field(converter=dict, default=()) + + +DC2(1, "f1", "f2", b"f3", []) # E +DC2("f0", "f1", "f2", 1, []) # E +DC2("f0", "f1", "f2", "f3", 3j) # E + + +dc1 = DC2("f0", "f1", "f2", b"f6", []) + +dc1.field0 = "f1" +dc1.field3 = "f6" +dc1.field3 = b"f6" + +dc1.field0 = 1 # E +dc1.field3 = 1 # E + +dc2 = DC2("f0", "f1", "f2", "f6", "1", (("a", "1"), ("b", "2"))) + + +# > If default or default_factory are provided, the type of the default value +# > should be assignable to the first positional parameter of the converter. + + +class DC3(ModelBase): + field0: int = model_field(converter=converter_simple, default="") + field1: int = model_field(converter=converter_simple, default=1) # E + + field2: int = model_field(converter=converter_simple, default_factory=str) + field3: int = model_field(converter=converter_simple, default_factory=int) # E