Fix inspect.getsource returning truncated source for multi-line function definitions#7519
Conversation
…co_firstlineno is correct Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/94701403-2011-4525-88f1-6e06891da6a4 Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
inspect.getsource returning truncated source for multi-line function definitions
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: (module 'gettext test_inspect' not found) Legend:
|
|
@Copilot CI is reporting some unexpected successes in |
|
@copilot CI is reporting some unexpected successes in Lib/test/test_gettext.py. Can you investigate if this is related to your change? |
… plural form tests Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/ce27bf53-569f-45a0-ad5a-08e8f322c717 Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
The test_gettext unexpected successes are pre-existing and unrelated to the
Not related to the |
| pass | ||
|
|
||
|
|
||
| source = inspect.getsource(a) |
There was a problem hiding this comment.
@copilot can you use a simple assertion since this source is very short?
such as
assert source == """\
def a(
a=0,
):
pass
"""
There was a problem hiding this comment.
@youknowone Is this the correct way to use copilot? How should I give feedback?
There was a problem hiding this comment.
not 100% sure, but i guess you must have copilot account and permission to the repository. probably you have to fork this repository to yours and run copilot on your fork.
youknowone
left a comment
There was a problem hiding this comment.
@copilot check failing tests again
…pect) Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/2b64da1b-8aab-4fec-8b28-3a21d46ac2f9 Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Checked the latest failed CI run (23672222911). The lint failure was formatting suggestions for |
inspect.getsourcereturned only the default-argument lines instead of the full source when a function had a multi-line parameter list. The underlying cause wasco_firstlinenobeing set to the default-argument line rather than thedefline.Root cause
In
compile_function_def, default arguments are compiled before the function scope is entered. Eachcompile_expression(default)call advancescurrent_source_rangeto the argument's source location. Whenpush_outputsubsequently callsget_source_line_number()to setfirstlineno, it picks up the default-argument line instead of thedefline.Changes
crates/codegen/src/compile.rs— Incompile_function_def, savecurrent_source_rangebefore compiling decorators/defaults and restore it before callingcompile_function_body, soco_firstlinenois anchored to thedefkeyword.Lib/test/test_inspect/test_inspect.py— Remove@unittest.expectedFailurefromtest_wrapped_decoratorandtest_parens_in_decorator, which now pass.Lib/test/test_gettext.py— Remove stale@unittest.expectedFailuredecorators from plural form tests that were already passing.Original prompt
This pull request was created from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.