From 18e45295c06eb97ea9299f6ea562600f98c4c221 2024-10-21 18:03:01 From: M Bussonnier Date: 2024-10-21 18:03:01 Subject: [PATCH] suggested fix for autocall failure (#14555) Closes : #14513 Following the recommendation in that Issue seems to fix the autocall issue (for at least the reproduction case) FYI: @Carreau since I saw you were assigned to the Issue. I only did the manual verification of the example case in the issue. --- diff --git a/IPython/core/prefilter.py b/IPython/core/prefilter.py index a29df0c..fc7b1c3 100644 --- a/IPython/core/prefilter.py +++ b/IPython/core/prefilter.py @@ -512,8 +512,10 @@ class AutocallChecker(PrefilterChecker): callable(oinfo.obj) and (not self.exclude_regexp.match(line_info.the_rest)) and self.function_name_regexp.match(line_info.ifun) - and line_info.raw_the_rest.startswith(" ") - or not line_info.raw_the_rest.strip() + and ( + line_info.raw_the_rest.startswith(" ") + or not line_info.raw_the_rest.strip() + ) ): return self.prefilter_manager.get_handler_by_name("auto") else: diff --git a/IPython/core/tests/test_prefilter.py b/IPython/core/tests/test_prefilter.py index 999cd43..379a530 100644 --- a/IPython/core/tests/test_prefilter.py +++ b/IPython/core/tests/test_prefilter.py @@ -137,3 +137,13 @@ def test_autocall_should_support_unicode(): finally: ip.run_line_magic("autocall", "0") del ip.user_ns["π"] + + +def test_autocall_regression_gh_14513(): + ip.run_line_magic("autocall", "2") + ip.user_ns["foo"] = dict() + try: + assert ip.prefilter("foo") == "foo" + finally: + ip.run_line_magic("autocall", "0") + del ip.user_ns["foo"]