failed NO_PATCH NO_PATCH UNSUBMITTED empty_patch(budget) · 25 tool calls · 308 s · fastapi/fastapi
🐛 Fix using class (not instance) dependency that has `__call__` method As reported in https://github.com/fastapi/fastapi/discussions/14452, FastAPI 0.123.6 introduced a regression - if we use class (not instance) as dependency and this class has `__call__` method that is coroutine or generator, it is mistakenly treated as coroutine\generator (actually class is not coroutine\generator, instance of this class is). So, to fix this we need to check if the callable is class before inspecting its `dunder_call` in `is_coroutine_callable`, `is_async_gen_callable`, and `is_gen_callable`.
| # | Tool | Arguments | Result |
|---|---|---|---|
| 1 | run_command | {
"command": "grep -rn \"is_coroutine_callable\" . | head -20"
} | {"status": "ok", "stdout": "./fastapi/dependencies/models.py:154: def is_coroutine_callable(self) -> bool:\n./fastapi/dependencies/utils.py:666: elif use_sub_defull{"status": "ok", "stdout": "./fastapi/dependencies/models.py:154: def is_coroutine_callable(self) -> bool:\n./fastapi/dependencies/utils.py:666: elif use_sub_dependant.is_coroutine_callable:\n./fastapi/routing.py:305: is_coroutine = dependant.is_coroutine_callable\n", "stderr": "", "exit_code": 0} |
| 2 | run_command | {
"command": "grep -nE \"is_coroutine_callable|is_async_gen_callable|is_gen_callable\" fastapi/dependencies/models.py"
} | {"status": "ok", "stdout": "106: def is_gen_callable(self) -> bool:\n130: def is_async_gen_callable(self) -> bool:\n154: def is_coroutine_callable(self) -> boolfull{"status": "ok", "stdout": "106: def is_gen_callable(self) -> bool:\n130: def is_async_gen_callable(self) -> bool:\n154: def is_coroutine_callable(self) -> bool:\n186: if self.is_gen_callable or self.is_async_gen_callable:\n", "stderr": "", "exit_code": 0} |
| 3 | run_command | {
"command": "sed -n '100,170p' fastapi/dependencies/models.py"
} | {"status": "ok", "stdout": " @cached_property\n def _security_dependencies(self) -> List[\"Dependant\"]:\n security_deps = [dep for dep in self.dependencies if full{"status": "ok", "stdout": " @cached_property\n def _security_dependencies(self) -> List[\"Dependant\"]:\n security_deps = [dep for dep in self.dependencies if dep._is_security_scheme]\n return security_deps\n\n @cached_property\n def is_gen_callable(self) -> bool:\n if self.call is None:\n return False # pragma: no cover\n if inspect.isgeneratorfunction(\n _impartial(self.call)\n ) or inspect.isgeneratorfunction(_unwrapped_call(self.call)):\n return True\n dunder_call = getattr(_impartial(self.call), \"__call__\", None) # noqa: B004\n if dunder_call is None:\n return False # pragma: no cover\n if inspect.isgeneratorfunction(\n _impartial(dunder_call)\n ) or inspect.isgeneratorfunction(_unwrapped_call(dunder_call)):\n return True\n dunder_unwrapped_call = getattr(_unwrapped_call(self.call), \"__call__\", None) # noqa: B004\n if dunder_unwrapped_call is None:\n return False # pragma: no cover\n if inspect.isgeneratorfunction(\n _impartial(dunder_unwrapped_call)\n ) or inspect.isgeneratorfunction(_unwrapped_call(dunder_unwrapped_call)):\n return True\n return False\n\n @cached_property\n def is_async_gen_callable(self) -> bool:\n if self.call is None:\n return False # pragma: no cover\n if inspect.isasyncgenfunction(\n _impartial(self.call)\n ) or inspect.isasyncgenfunction(_unwrapped_call(self.call)):\n return True\n dunder_call = getattr(_impartial(self.call), \"__call__\", None) # noqa: B004\n if dunder_call is None:\n return False # pragma: no cover\n if inspect.isasyncgenfunction(\n _impartial(dunder_call)\n ) or inspect.isasyncgenfunction(_unwrapped_call(dunder_call)):\n return True\n dunder_unwrapped_call = getattr(_unwrap |
| 4 | run_command | {
"command": "sed -n '154,185p' fastapi/dependencies/models.py"
} | {"status": "ok", "stdout": " def is_coroutine_callable(self) -> bool:\n if self.call is None:\n return False # pragma: no cover\n if inspect.isroutine(_impartiafull{"status": "ok", "stdout": " def is_coroutine_callable(self) -> bool:\n if self.call is None:\n return False # pragma: no cover\n if inspect.isroutine(_impartial(self.call)) and iscoroutinefunction(\n _impartial(self.call)\n ):\n return True\n if inspect.isroutine(_unwrapped_call(self.call)) and iscoroutinefunction(\n _unwrapped_call(self.call)\n ):\n return True\n dunder_call = getattr(_impartial(self.call), \"__call__\", None) # noqa: B004\n if dunder_call is None:\n return False # pragma: no cover\n if iscoroutinefunction(_impartial(dunder_call)) or iscoroutinefunction(\n _unwrapped_call(dunder_call)\n ):\n return True\n dunder_unwrapped_call = getattr(_unwrapped_call(self.call), \"__call__\", None) # noqa: B004\n if dunder_unwrapped_call is None:\n return False # pragma: no cover\n if iscoroutinefunction(\n _impartial(dunder_unwrapped_call)\n ) or iscoroutinefunction(_unwrapped_call(dunder_unwrapped_call)):\n return True\n # if inspect.isclass(self.call): False, covered by default return\n return False\n\n @cached_property\n def computed_scope(self) -> Union[str, None]:\n if self.scope:\n return self.scope\n", "stderr": "", "exit_code": 0} |
| 5-6 ×2 | run_command | {
"command": "python3 -c \"\nimport inspect\nfrom typing import Any\n\ndef iscoroutinefunction(func):\n return inspect.iscoroutinefunction(func)\n\nclass MyCallable:\n async def __call__(self):\n pass\n\ndef test():\n # Case 1: Instance of MyCallable\n instance = MyCallable()\n print(f'Instance iscoroutinefunction: {iscoroutinefunction(instance)}')\n \n # Case 2: Class MyCallable\n print(f'Class iscoroutinefunction: {iscoroutinefunction(MyCallable)}')\n \n # Case 3: MyCallable.__call__\n print(f'MyCallable.__call__ iscoroutinefunction: {iscoroutinefunction(MyCallable.__call__)}')\n\ntest()\n\""
} | {"status": "ok", "stdout": "Instance iscoroutinefunction: False\nClass iscoroutinefunction: False\nMyCallable.__call__ iscoroutinefunction: True\n", "stderr": "full{"status": "ok", "stdout": "Instance iscoroutinefunction: False\nClass iscoroutinefunction: False\nMyCallable.__call__ iscoroutinefunction: True\n", "stderr": "", "exit_code": 0} |
| 7 | run_command | {
"command": "python3 -c \"\nimport inspect\n\ndef iscoroutinefunction(func):\n return inspect.iscoroutinefunction(func)\n\nclass MyCallable:\n async def __call__(self):\n pass\n\n# In FastAPI's is_coroutine_callable:\n# self.call = MyCallable (the class)\ncall = MyCallable\n\n# dunder_call = getattr(call, '__call__', None)\ndunder_call = getattr(call, '__call__', None)\nprint(f'dunder_call: {dunder_call}')\nprint(f'iscoroutinefunction(dunder_call): {iscoroutinefunction(dunder_call)}')\n\""
} | {"status": "ok", "stdout": "dunder_call: <function MyCallable.__call__ at 0x7b83aea6bf60>\niscoroutinefunction(dunder_call): True\n", "stderr": "", "exit_code":full{"status": "ok", "stdout": "dunder_call: <function MyCallable.__call__ at 0x7b83aea6bf60>\niscoroutinefunction(dunder_call): True\n", "stderr": "", "exit_code": 0} |
| 8 | run_command | {
"command": "python3 -c \"\nimport inspect\n\ndef iscoroutinefunction(func):\n return inspect.iscoroutinefunction(func)\n\nclass MyCallable:\n async def __call__(self):\n pass\n\n# Case 1: self.call is the class\ncall = MyCallable\ndunder_call = getattr(call, '__call__', None)\nprint(f'Class: iscoroutinefunction(dunder_call) = {iscoroutinefunction(dunder_call)}')\n\n# Case 2: self.call is an instance\ninstance = MyCallable()\ndunder_call_inst = getattr(instance, '__call__', None)\nprint(f'Instance: iscoroutinefunction(dunder_call_inst) = {iscoroutinefunction(dunder_call_inst)}')\n\""
} | {"status": "ok", "stdout": "Class: iscoroutinefunction(dunder_call) = True\nInstance: iscoroutinefunction(dunder_call_inst) = True\n", "stderr": "", "exit_code"full{"status": "ok", "stdout": "Class: iscoroutinefunction(dunder_call) = True\nInstance: iscoroutinefunction(dunder_call_inst) = True\n", "stderr": "", "exit_code": 0} |
| 9 | run_command | {
"command": "python3 -c \"\nimport inspect\n\ndef iscoroutinefunction(func):\n return inspect.iscoroutinefunction(func)\n\nclass MyCallable:\n async def __call__(self):\n pass\n\n# If self.call is the class, we should NOT treat it as a coroutine callable\n# because FastAPI will instantiate it first.\n# If self.call is an instance, we SHOULD treat it as a coroutine callable\n# because it will be called directly.\n\ncall_class = MyCallable\ncall_instance = MyCallable()\n\ndef is_coroutine_callable_mock(call):\n if call is None: return False\n # ... (simplified)\n dunder_call = getattr(call, '__call__', None)\n if dunder_call is None: return False\n if iscoroutinefunction(dunder_call):\n return True\n return False\n\nprint(f'Class: {is_coroutine_callable_mock(call_class)}')\nprint(f'Instance: {is_coroutine_callable_mock(call_instance)}')\n\""
} | {"status": "ok", "stdout": "Class: True\nInstance: True\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "Class: True\nInstance: True\n", "stderr": "", "exit_code": 0} |
| 10 | run_command | {
"command": "python3 -c \"\nimport inspect\n\ndef iscoroutinefunction(func):\n return inspect.iscoroutinefunction(func)\n\nclass MyCallable:\n async def __call__(self):\n pass\n\ncall_class = MyCallable\ncall_instance = MyCallable()\n\ndef is_coroutine_callable_fixed_mock(call):\n if call is None: return False\n # ... (simplified)\n if inspect.isclass(call):\n return False # If it's a class, it's not a coroutine callable itself, its instance might be.\n \n dunder_call = getattr(call, '__call__', None)\n if dunder_call is None: return False\n if iscoroutinefunction(dunder_call):\n return True\n return False\n\nprint(f'Class: {is_coroutine_callable_fixed_mock(call_class)}')\nprint(f'Instance: {is_coroutine_callable_fixed_mock(call_instance)}')\n\""
} | {"status": "ok", "stdout": "Class: False\nInstance: True\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "Class: False\nInstance: True\n", "stderr": "", "exit_code": 0} |
| 11 | run_command | {
"command": "sed -n '106,153p' fastapi/dependencies/models.py"
} | {"status": "ok", "stdout": " def is_gen_callable(self) -> bool:\n if self.call is None:\n return False # pragma: no cover\n if inspect.isgeneratorfunction(\n _ifull{"status": "ok", "stdout": " def is_gen_callable(self) -> bool:\n if self.call is None:\n return False # pragma: no cover\n if inspect.isgeneratorfunction(\n _impartial(self.call)\n ) or inspect.isgeneratorfunction(_unwrapped_call(self.call)):\n return True\n dunder_call = getattr(_impartial(self.call), \"__call__\", None) # noqa: B004\n if dunder_call is None:\n return False # pragma: no cover\n if inspect.isgeneratorfunction(\n _impartial(dunder_call)\n ) or inspect.isgeneratorfunction(_unwrapped_call(dunder_call)):\n return True\n dunder_unwrapped_call = getattr(_unwrapped_call(self.call), \"__call__\", None) # noqa: B004\n if dunder_unwrapped_call is None:\n return False # pragma: no cover\n if inspect.isgeneratorfunction(\n _impartial(dunder_unwrapped_call)\n ) or inspect.isgeneratorfunction(_unwrapped_call(dunder_unwrapped_call)):\n return True\n return False\n\n @cached_property\n def is_async_gen_callable(self) -> bool:\n if self.call is None:\n return False # pragma: no cover\n if inspect.isasyncgenfunction(\n _impartial(self.call)\n ) or inspect.isasyncgenfunction(_unwrapped_call(self.call)):\n return True\n dunder_call = getattr(_impartial(self.call), \"__call__\", None) # noqa: B004\n if dunder_call is None:\n return False # pragma: no cover\n if inspect.isasyncgenfunction(\n _impartial(dunder_call)\n ) or inspect.isasyncgenfunction(_unwrapped_call(dunder_call)):\n return True\n dunder_unwrapped_call = getattr(_unwrapped_call(self.call), \"__call__\", None) # noqa: B004\n if dunder_unwrapped_call is None:\n return False # pragma: no cover\n if inspect.isasyncgenfunction(\n _impartial(dunder_unwrapped_ |
| 12 | run_command | {
"command": "sed -n '154,185p' fastapi/dependencies/models.py"
} | {"status": "ok", "stdout": " def is_coroutine_callable(self) -> bool:\n if self.call is None:\n return False # pragma: no cover\n if inspect.isroutine(_impartiafull{"status": "ok", "stdout": " def is_coroutine_callable(self) -> bool:\n if self.call is None:\n return False # pragma: no cover\n if inspect.isroutine(_impartial(self.call)) and iscoroutinefunction(\n _impartial(self.call)\n ):\n return True\n if inspect.isroutine(_unwrapped_call(self.call)) and iscoroutinefunction(\n _unwrapped_call(self.call)\n ):\n return True\n dunder_call = getattr(_impartial(self.call), \"__call__\", None) # noqa: B004\n if dunder_call is None:\n return False # pragma: no cover\n if iscoroutinefunction(_impartial(dunder_call)) or iscoroutinefunction(\n _unwrapped_call(dunder_call)\n ):\n return True\n dunder_unwrapped_call = getattr(_unwrapped_call(self.call), \"__call__\", None) # noqa: B004\n if dunder_unwrapped_call is None:\n return False # pragma: no cover\n if iscoroutinefunction(\n _impartial(dunder_unwrapped_call)\n ) or iscoroutinefunction(_unwrapped_call(dunder_unwrapped_call)):\n return True\n # if inspect.isclass(self.call): False, covered by default return\n return False\n\n @cached_property\n def computed_scope(self) -> Union[str, None]:\n if self.scope:\n return self.scope\n", "stderr": "", "exit_code": 0} |
| 13 | run_command | {
"command": "python3 -c \"\nimport inspect\nfrom typing import Any\n\ndef isgeneratorfunction(func):\n return inspect.isgeneratorfunction(func)\n\nclass MyCallable:\n def __call__(self):\n yield 1\n\ndef test():\n call_class = MyCallable\n call_instance = MyCallable()\n \n dunder_call_class = getattr(call_class, '__call__', None)\n dunder_call_inst = getattr(call_instance, '__call__', None)\n \n print(f'Class dunder_call is generator: {isgeneratorfunction(dunder_call_class)}')\n print(f'Instance dunder_call is generator: {isgeneratorfunction(dunder_call_inst)}')\n\ntest()\n\""
} | {"status": "ok", "stdout": "Class dunder_call is generator: True\nInstance dunder_call is generator: True\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "Class dunder_call is generator: True\nInstance dunder_call is generator: True\n", "stderr": "", "exit_code": 0} |
| 14 | run_command | {
"command": "python3 -c \"\nimport inspect\n\ndef isasyncgenfunction(func):\n return inspect.isasyncgenfunction(func)\n\nclass MyCallable:\n async def __call__(self):\n yield 1\n\ndef test():\n call_class = MyCallable\n call_instance = MyCallable()\n \n dunder_call_class = getattr(call_class, '__call__', None)\n dunder_call_inst = getattr(call_instance, '__call__', None)\n \n print(f'Class dunder_call is async gen: {isasyncgenfunction(dunder_call_class)}')\n print(f'Instance dunder_call is async gen: {isasyncgenfunction(dunder_call_inst)}')\n\ntest()\n\""
} | {"status": "ok", "stdout": "Class dunder_call is async gen: True\nInstance dunder_call is async gen: True\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "Class dunder_call is async gen: True\nInstance dunder_call is async gen: True\n", "stderr": "", "exit_code": 0} |
| 15 | run_command | {
"command": "python3 -c \"\nimport inspect\nfrom typing import Any\n\ndef iscoroutinefunction(func):\n return inspect.iscoroutinefunction(func)\n\nclass MyCallable:\n async def __call__(self):\n pass\n\n# In FastAPI's is_coroutine_callable:\n# self.call = MyCallable (the class)\ncall = MyCallable\n\n# dunder_call = getattr(call, '__call__', None)\ndunder_call = getattr(call, '__call__', None)\nprint(f'dunder_call: {dunder_call}')\nprint(f'iscoroutinefunction(dunder_call): {iscoroutinefunction(dunder_call)}')\n\""
} | {"status": "ok", "stdout": "dunder_call: <function MyCallable.__call__ at 0x7d5a88297f60>\niscoroutinefunction(dunder_call): True\n", "stderr": "", "exit_code":full{"status": "ok", "stdout": "dunder_call: <function MyCallable.__call__ at 0x7d5a88297f60>\niscoroutinefunction(dunder_call): True\n", "stderr": "", "exit_code": 0} |
| 16 | run_command | {
"command": "python3 -c \"\nimport inspect\n\ndef iscoroutinefunction(func):\n return inspect.iscoroutinefunction(func)\n\nclass MyCallable:\n async def __call__(self):\n pass\n\n# If self.call is the class, we should NOT treat it as a coroutine callable\n# because FastAPI will instantiate it first.\n# If self.call is an instance, we SHOULD treat it as a coroutine callable\n# because it will be called directly.\n\ncall_class = MyCallable\ncall_instance = MyCallable()\n\ndef is_coroutine_callable_mock(call):\n if call is None: return False\n # ... (simplified)\n dunder_call = getattr(call, '__call__', None)\n if dunder_call is None: return False\n if iscoroutinefunction(dunder_call):\n return True\n return False\n\nprint(f'Class: {is_coroutine_callable_mock(call_class)}')\nprint(f'Instance: {is_coroutine_callable_mock(call_instance)}')\n\""
} | {"status": "ok", "stdout": "Class: True\nInstance: True\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "Class: True\nInstance: True\n", "stderr": "", "exit_code": 0} |
| 17 | run_command | {
"command": "python3 -c \"\nimport inspect\n\ndef iscoroutinefunction(func):\n return inspect.iscoroutinefunction(func)\n\nclass MyCallable:\n async def __call__(self):\n pass\n\n# If self.call is the class, we should NOT treat it as a coroutine callable\n# because FastAPI will instantiate it first.\n# If self.call is an instance, we SHOULD treat it as a coroutine callable\n# because it will be called directly.\n\ncall_class = MyCallable\ncall_instance = MyCallable()\n\ndef is_coroutine_callable_fixed_mock(call):\n if call is None: return False\n # ... (simplified)\n if inspect.isclass(call):\n return False # If it's a class, it's not a coroutine callable itself, its instance might be.\n \n dunder_call = getattr(call, '__call__', None)\n if dunder_call is None: return False\n if iscoroutinefunction(dunder_call):\n return True\n return False\n\nprint(f'Class: {is_coroutine_callable_fixed_mock(call_class)}')\nprint(f'Instance: {is_coroutine_callable_fixed_mock(call_instance)}')\n\""
} | {"status": "ok", "stdout": "Class: False\nInstance: True\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "Class: False\nInstance: True\n", "stderr": "", "exit_code": 0} |
| 18 | run_command | {
"command": "python3 -c \"\nimport inspect\n\ndef isgeneratorfunction(func):\n return inspect.isgeneratorfunction(func)\n\nclass MyCallable:\n def __call__(self):\n yield 1\n\ncall_class = MyCallable\ncall_instance = MyCallable()\n\ndef is_gen_callable_mock(call):\n if call is None: return False\n # ... (simplified)\n dunder_call = getattr(call, '__call__', None)\n if dunder_call is None: return False\n if isgeneratorfunction(dunder_call):\n return True\n return False\n\nprint(f'Class: {is_gen_callable_mock(call_class)}')\nprint(f'Instance: {is_gen_callable_mock(call_instance)}')\n\""
} | {"status": "ok", "stdout": "Class: True\nInstance: True\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "Class: True\nInstance: True\n", "stderr": "", "exit_code": 0} |
| 19 | run_command | {
"command": "python3 -c \"\nimport inspect\n\ndef isgeneratorfunction(func):\n return inspect.isgeneratorfunction(func)\n\nclass MyCallable:\n def __call__(self):\n yield 1\n\ncall_class = MyCallable\ncall_instance = MyCallable()\n\ndef is_gen_callable_fixed_mock(call):\n if call is None: return False\n # ... (simplified)\n if inspect.isclass(call):\n return False\n \n dunder_call = getattr(call, '__call__', None)\n if dunder_call is None: return False\n if isgeneratorfunction(dunder_call):\n return True\n return False\n\nprint(f'Class: {is_gen_callable_fixed_mock(call_class)}')\nprint(f'Instance: {is_gen_callable_fixed_mock(call_instance)}')\n\""
} | {"status": "ok", "stdout": "Class: False\nInstance: True\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "Class: False\nInstance: True\n", "stderr": "", "exit_code": 0} |
| 20 | run_command | {
"command": "python3 -c \"\nimport inspect\n\ndef isasyncgenfunction(func):\n return inspect.isasyncgenfunction(func)\n\nclass MyCallable:\n async def __call__(self):\n yield 1\n\ncall_class = MyCallable\ncall_instance = MyCallable()\n\ndef is_async_gen_callable_mock(call):\n if call is None: return False\n # ... (simplified)\n dunder_call = getattr(call, '__call__', None)\n if dunder_call is None: return False\n if isasyncgenfunction(dunder_call):\n return True\n return False\n\nprint(f'Class: {is_async_gen_callable_mock(call_class)}')\nprint(f'Instance: {is_async_gen_callable_mock(call_instance)}')\n\""
} | {"status": "ok", "stdout": "Class: True\nInstance: True\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "Class: True\nInstance: True\n", "stderr": "", "exit_code": 0} |
| 21 | run_command | {
"command": "python3 -c \"\nimport inspect\n\ndef isasyncgenfunction(func):\n return inspect.isasyncgenfunction(func)\n\nclass MyCallable:\n async def __call__(self):\n yield 1\n\ncall_class = MyCallable\ncall_instance = MyCallable()\n\ndef is_async_gen_callable_fixed_mock(call):\n if call is None: return False\n # ... (simplified)\n if inspect.isclass(call):\n return False\n \n dunder_call = getattr(call, '__call__', None)\n if dunder_call is None: return False\n if isasyncgenfunction(dunder_call):\n return True\n return False\n\nprint(f'Class: {is_async_gen_callable_fixed_mock(call_class)}')\nprint(f'Instance: {is_async_gen_callable_fixed_mock(call_instance)}')\n\""
} | {"status": "ok", "stdout": "Class: False\nInstance: True\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "Class: False\nInstance: True\n", "stderr": "", "exit_code": 0} |
| 22 | run_command | {
"command": "sed -n '106,185p' fastapi/dependencies/models.py"
} | {"status": "ok", "stdout": " def is_gen_callable(self) -> bool:\n if self.call is None:\n return False # pragma: no cover\n if inspect.isgeneratorfunction(\n _ifull{"status": "ok", "stdout": " def is_gen_callable(self) -> bool:\n if self.call is None:\n return False # pragma: no cover\n if inspect.isgeneratorfunction(\n _impartial(self.call)\n ) or inspect.isgeneratorfunction(_unwrapped_call(self.call)):\n return True\n dunder_call = getattr(_impartial(self.call), \"__call__\", None) # noqa: B004\n if dunder_call is None:\n return False # pragma: no cover\n if inspect.isgeneratorfunction(\n _impartial(dunder_call)\n ) or inspect.isgeneratorfunction(_unwrapped_call(dunder_call)):\n return True\n dunder_unwrapped_call = getattr(_unwrapped_call(self.call), \"__call__\", None) # noqa: B004\n if dunder_unwrapped_call is None:\n return False # pragma: no cover\n if inspect.isgeneratorfunction(\n _impartial(dunder_unwrapped_call)\n ) or inspect.isgeneratorfunction(_unwrapped_call(dunder_unwrapped_call)):\n return True\n return False\n\n @cached_property\n def is_async_gen_callable(self) -> bool:\n if self.call is None:\n return False # pragma: no cover\n if inspect.isasyncgenfunction(\n _impartial(self.call)\n ) or inspect.isasyncgenfunction(_unwrapped_call(self.call)):\n return True\n dunder_call = getattr(_impartial(self.call), \"__call__\", None) # noqa: B004\n if dunder_call is None:\n return False # pragma: no cover\n if inspect.isasyncgenfunction(\n _impartial(dunder_call)\n ) or inspect.isasyncgenfunction(_unwrapped_call(dunder_call)):\n return True\n dunder_unwrapped_call = getattr(_unwrapped_call(self.call), \"__call__\", None) # noqa: B004\n if dunder_unwrapped_call is None:\n return False # pragma: no cover\n if inspect.isasyncgenfunction(\n _impartial(dunder_unwrapped_ |
| 23 | run_command | {
"command": "python3 -c \"\nimport inspect\nfrom typing import Any\n\ndef iscoroutinefunction(func):\n return inspect.iscoroutinefunction(func)\n\nclass MyCallable:\n async def __call__(self):\n pass\n\n# In FastAPI's is_coroutine_callable:\n# self.call = MyCallable (the class)\ncall = MyCallable\n\n# dunder_call = getattr(call, '__call__', None)\ndunder_call = getattr(call, '__call__', None)\nprint(f'dunder_call: {dunder_call}')\nprint(f'iscoroutinefunction(dunder_call): {iscoroutinefunction(dunder_call)}')\n\""
} | {"status": "ok", "stdout": "dunder_call: <function MyCallable.__call__ at 0x7876100e3f60>\niscoroutinefunction(dunder_call): True\n", "stderr": "", "exit_code":full{"status": "ok", "stdout": "dunder_call: <function MyCallable.__call__ at 0x7876100e3f60>\niscoroutinefunction(dunder_call): True\n", "stderr": "", "exit_code": 0} |
| 24 | run_command | {
"command": "python3 -c \"\nimport inspect\n\ndef iscoroutinefunction(func):\n return inspect.iscoroutinefunction(func)\n\nclass MyCallable:\n async def __call__(self):\n pass\n\n# If self.call is the class, we should NOT treat it as a coroutine callable\n# because FastAPI will instantiate it first.\n# If self.call is an instance, we SHOULD treat it as a coroutine callable\n# because it will be called directly.\n\ncall_class = MyCallable\ncall_instance = MyCallable()\n\ndef is_coroutine_callable_mock(call):\n if call is None: return False\n # ... (simplified)\n dunder_call = getattr(call, '__call__', None)\n if dunder_call is None: return False\n if iscoroutinefunction(dunder_call):\n return True\n return False\n\nprint(f'Class: {is_coroutine_callable_mock(call_class)}')\nprint(f'Instance: {is_coroutine_callable_mock(call_instance)}')\n\""
} | {"status": "ok", "stdout": "Class: True\nInstance: True\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "Class: True\nInstance: True\n", "stderr": "", "exit_code": 0} |
| 25 | run_command | {
"command": "python3 -c \"\nimport inspect\n\ndef iscoroutinefunction(func):\n return inspect.iscoroutinefunction(func)\n\nclass MyCallable:\n async def __call__(self):\n pass\n\n# If self.call is the class, we should NOT treat it as a coroutine callable\n# because FastAPI will instantiate it first.\n# If self.call is an instance, we SHOULD treat it as a coroutine callable\n# because it will be called directly.\n\ncall_class = MyCallable\ncall_instance = MyCallable()\n\ndef is_coroutine_callable_fixed_mock(call):\n if call is None: return False\n # ... (simplified)\n if inspect.isclass(call):\n return False # If it's a class, it's not a coroutine callable itself, its instance might be.\n \n dunder_call = getattr(call, '__call__', None)\n if dunder_call is None: return False\n if iscoroutinefunction(dunder_call):\n return True\n return False\n\nprint(f'Class: {is_coroutine_callable_fixed_mock(call_class)}')\nprint(f'Instance: {is_coroutine_callable_fixed_mock(call_instance)}')\n\""
} | {"status": "ok", "stdout": "Class: False\nInstance: True\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "Class: False\nInstance: True\n", "stderr": "", "exit_code": 0} |