Skip to content

getsource crash in Python 3.14 REPL #745

Description

@pomponchik

Hi!

I opened the REPL and typed the following code:

>>> from dill.source import getsource as dill_getsource
>>>
>>>
>>> def f():
...     pass
...
>>> dill_getsource(f)
Traceback (most recent call last):
  File "<python-input-4>", line 1, in <module>
    dill_getsource(f)
    ~~~~~~~~~~~~~~^^^
  File "/Users/pomponchik/Desktop/Projects/symplug/venv/lib/python3.14/site-packages/dill/source.py", line 374, in getsource
    lines, lnum = getsourcelines(object, enclosing=enclosing)
                  ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pomponchik/Desktop/Projects/symplug/venv/lib/python3.14/site-packages/dill/source.py", line 345, in getsourcelines
    code, n = getblocks(object, lstrip=lstrip, enclosing=enclosing, locate=True)
              ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pomponchik/Desktop/Projects/symplug/venv/lib/python3.14/site-packages/dill/source.py", line 271, in getblocks
    lines, lnum = findsource(object)
                  ~~~~~~~~~~^^^^^^^^
  File "/Users/pomponchik/Desktop/Projects/symplug/venv/lib/python3.14/site-packages/dill/source.py", line 176, in findsource
    raise IOError('could not extract source code')
OSError: could not extract source code

As you can see, I got an error.

My operating system is macOS. Python version is 3.14.2 (version 3.14.2:df793163d58, December 5 2025, 12:18:06). Dill’s version is 0.4.0 (i also tried 0.4.1, the result is the same).

I also tried to do the same thing on the same computer, but using Python 3.10, and everything was fine:

Python 3.10.8 (v3.10.8:aaaf517424, Oct 11 2022, 10:14:40) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from dill.source import getsource as dill_getsource
>>>
>>> def f():
...     pass
...
>>> dill_getsource(f)
'def f():\n\tpass\n'
>>>

By the way, I also looked at the tests, and I did not find a test that would check the behavior of dill.source.getsource in the REPL.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions