diff options
author | Brandt Bucher <brandtbucher@microsoft.com> | 2023-05-04 22:07:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-04 22:07:42 (GMT) |
commit | 7d35c3121ade679dd6e8b4a0bac7b3702aee6921 (patch) | |
tree | 85e22e1940226bf45e95e7dbe334e966c659f196 /Lib | |
parent | f5c38382f9c40f0017cef086896a8160e313ac9e (diff) | |
download | cpython-7d35c3121ade679dd6e8b4a0bac7b3702aee6921.zip cpython-7d35c3121ade679dd6e8b4a0bac7b3702aee6921.tar.gz cpython-7d35c3121ade679dd6e8b4a0bac7b3702aee6921.tar.bz2 |
GH-103899: Provide a hint when accidentally calling a module (GH-103900)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_call.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_call.py b/Lib/test/test_call.py index aab7b15..12759c5 100644 --- a/Lib/test/test_call.py +++ b/Lib/test/test_call.py @@ -10,6 +10,7 @@ import itertools import gc import contextlib import sys +import types class BadStr(str): @@ -202,6 +203,37 @@ class CFunctionCallsErrorMessages(unittest.TestCase): msg = r"count\(\) takes no keyword arguments" self.assertRaisesRegex(TypeError, msg, [].count, x=2, y=2) + def test_object_not_callable(self): + msg = r"^'object' object is not callable$" + self.assertRaisesRegex(TypeError, msg, object()) + + def test_module_not_callable_no_suggestion_0(self): + msg = r"^'module' object is not callable$" + self.assertRaisesRegex(TypeError, msg, types.ModuleType("mod")) + + def test_module_not_callable_no_suggestion_1(self): + msg = r"^'module' object is not callable$" + mod = types.ModuleType("mod") + mod.mod = 42 + self.assertRaisesRegex(TypeError, msg, mod) + + def test_module_not_callable_no_suggestion_2(self): + msg = r"^'module' object is not callable$" + mod = types.ModuleType("mod") + del mod.__name__ + self.assertRaisesRegex(TypeError, msg, mod) + + def test_module_not_callable_no_suggestion_3(self): + msg = r"^'module' object is not callable$" + mod = types.ModuleType("mod") + mod.__name__ = 42 + self.assertRaisesRegex(TypeError, msg, mod) + + def test_module_not_callable_suggestion(self): + msg = r"^'module' object is not callable\. Did you mean: 'mod\.mod\(\.\.\.\)'\?$" + mod = types.ModuleType("mod") + mod.mod = lambda: ... + self.assertRaisesRegex(TypeError, msg, mod) class TestCallingConventions(unittest.TestCase): |