Skip to content

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

Closed

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)

Activity

  1. fanninpm commented on Mar 27, 2026

    @fanninpm
    Contributor

    This is being worked on in #7519.

  2. youknowone commented on Mar 30, 2026

    @youknowone
    Member

    Fixed by #7519, thank you for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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