Skip to content

inspect.getsource does not return full source for some functions #7517

@DRMacIver

Description

@DRMacIver

Summary

inspect.getsource does not return full source for some(?) functions

Verified on commit 3dae07c built in release mode with rustc 1.93.0.

Expected

"""
import inspect

def a(
    a=0,
):
    0

a = inspect.getsource(a)

print(a)

# getsource should return the full source including "def a(",
# but RustPython returns only "a=0,\n):    0\n" (the last lines)
assert "def" in a, f"Expected full source, got: {a!r}"

This should (and does on cpython) print the following:

def a(
    a=0,
):
    0
    a=0,

Traceback (most recent call last):
  File "/Users/drmaciver/Projects/hypothesis/rustpython-bugs/bug1_getsource_truncated.py", line 26, in <module>
    assert "def" in a, f"Expected full source, got: {a!r}"
                                                     ^
AssertionError: Expected full source, got: '    a=0,\n'

Python Documentation

(https://docs.python.org/3/library/inspect.html#inspect.getsource)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions