From c67346d0443d12ecfdc76490f95f9c0c4517544e Mon Sep 17 00:00:00 2001 From: Rodrigo Silva Date: Thu, 2 Feb 2023 16:26:14 -0300 Subject: [PATCH 1/3] Improve misleading message in Enum() (#5317) Clarifying this is a mypy limitation, not an Enum() requirement. --- mypy/semanal_enum.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mypy/semanal_enum.py b/mypy/semanal_enum.py index d48e620b89f1..93454e424c6f 100644 --- a/mypy/semanal_enum.py +++ b/mypy/semanal_enum.py @@ -220,14 +220,14 @@ def parse_enum_call_args( items.append(field) else: return self.fail_enum_call_arg( - "%s() expects a string, tuple, list or dict literal as the second argument" + "Non-literal string, tuple, list or dict as the second argument of %s() is not supported" % class_name, call, ) else: # TODO: Allow dict(x=1, y=2) as a substitute for {'x': 1, 'y': 2}? return self.fail_enum_call_arg( - "%s() expects a string, tuple, list or dict literal as the second argument" + "Non-literal string, tuple, list or dict as the second argument of %s() is not supported" % class_name, call, ) From 00d420d9b84dae81da9e32593aba6990e5221d15 Mon Sep 17 00:00:00 2001 From: Rodrigo Silva Date: Thu, 2 Feb 2023 16:44:26 -0300 Subject: [PATCH 2/3] Update messages in Enum() tests --- test-data/unit/check-enum.test | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test-data/unit/check-enum.test b/test-data/unit/check-enum.test index 9343e8d5c562..6e0b5fd2df24 100644 --- a/test-data/unit/check-enum.test +++ b/test-data/unit/check-enum.test @@ -482,13 +482,13 @@ W.c [typing fixtures/typing-medium.pyi] [out] main:2: error: Too few arguments for Enum() -main:3: error: Enum() expects a string, tuple, list or dict literal as the second argument +main:3: error: Non-literal string, tuple, list or dict as the second argument of Enum() is not supported main:4: error: Too many arguments for Enum() -main:5: error: Enum() expects a string, tuple, list or dict literal as the second argument +main:5: error: Non-literal string, tuple, list or dict as the second argument of Enum() is not supported main:5: error: Name "foo" is not defined -main:7: error: Enum() expects a string, tuple, list or dict literal as the second argument +main:7: error: Non-literal string, tuple, list or dict as the second argument of Enum() is not supported main:8: error: Too few arguments for IntEnum() -main:9: error: IntEnum() expects a string, tuple, list or dict literal as the second argument +main:9: error: Non-literal string, tuple, list or dict as the second argument of IntEnum() is not supported main:10: error: Too many arguments for IntEnum() main:11: error: Enum() needs at least one item main:12: error: Enum() needs at least one item From 54b319e3e88f9cdc3d013e0d369c3897971b4718 Mon Sep 17 00:00:00 2001 From: MestreLion Date: Thu, 2 Feb 2023 19:33:36 -0300 Subject: [PATCH 3/3] rephasing message as requested by @hauntsaninja --- mypy/semanal_enum.py | 4 ++-- test-data/unit/check-enum.test | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mypy/semanal_enum.py b/mypy/semanal_enum.py index 93454e424c6f..c7b8e44f65aa 100644 --- a/mypy/semanal_enum.py +++ b/mypy/semanal_enum.py @@ -220,14 +220,14 @@ def parse_enum_call_args( items.append(field) else: return self.fail_enum_call_arg( - "Non-literal string, tuple, list or dict as the second argument of %s() is not supported" + "Second argument of %s() must be string, tuple, list or dict literal for mypy to determine Enum members" % class_name, call, ) else: # TODO: Allow dict(x=1, y=2) as a substitute for {'x': 1, 'y': 2}? return self.fail_enum_call_arg( - "Non-literal string, tuple, list or dict as the second argument of %s() is not supported" + "Second argument of %s() must be string, tuple, list or dict literal for mypy to determine Enum members" % class_name, call, ) diff --git a/test-data/unit/check-enum.test b/test-data/unit/check-enum.test index 6e0b5fd2df24..80a7ca7ff99f 100644 --- a/test-data/unit/check-enum.test +++ b/test-data/unit/check-enum.test @@ -482,13 +482,13 @@ W.c [typing fixtures/typing-medium.pyi] [out] main:2: error: Too few arguments for Enum() -main:3: error: Non-literal string, tuple, list or dict as the second argument of Enum() is not supported +main:3: error: Second argument of Enum() must be string, tuple, list or dict literal for mypy to determine Enum members main:4: error: Too many arguments for Enum() -main:5: error: Non-literal string, tuple, list or dict as the second argument of Enum() is not supported +main:5: error: Second argument of Enum() must be string, tuple, list or dict literal for mypy to determine Enum members main:5: error: Name "foo" is not defined -main:7: error: Non-literal string, tuple, list or dict as the second argument of Enum() is not supported +main:7: error: Second argument of Enum() must be string, tuple, list or dict literal for mypy to determine Enum members main:8: error: Too few arguments for IntEnum() -main:9: error: Non-literal string, tuple, list or dict as the second argument of IntEnum() is not supported +main:9: error: Second argument of IntEnum() must be string, tuple, list or dict literal for mypy to determine Enum members main:10: error: Too many arguments for IntEnum() main:11: error: Enum() needs at least one item main:12: error: Enum() needs at least one item