Skip to content

save_session() broken when cython changes #37003

@tornaria

Description

@tornaria

I can't test this interactively due to #37002, but I found the following doctest failure:

**********************************************************************
File "src/sage/misc/session.pyx", line 303, in sage.misc.session.save_session
Failed example:
    save_session(tmp_f, verbose=True)
Expected:
    Saving...
    Not saving g: g is a function, method, class or type
    ...
Got:
    Saving __cached__
    Saving __doc__
    Saving __file__
    Saving __loader__
    Saving __name__
    Saving __spec__
    Saving a
    Not saving checkbox: checkbox is a function, method, class or type
    Not saving color_selector: color_selector is a function, method, class or type
    Not saving f: f is a function, method, class or type
    Saving g
    Not saving input_box: input_box is a function, method, class or type
    Not saving input_grid: input_grid is a function, method, class or type
    Saving interact
    Not saving range_slider: range_slider is a function, method, class or type
    Not saving selector: selector is a function, method, class or type
    Not saving slider: slider is a function, method, class or type
    Not saving text_control: text_control is a function, method, class or type
    Saving tmp_f
**********************************************************************

The issue here is that g is a cython function and according to the doctest should not be saved, but it is.

Further investigation reveals the following:

$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 10.2, Release Date: 2023-12-03                    │
│ Using Python 3.12.1. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
sage: g = cython_lambda('double x', 'x*x + 1.5')
sage: type(g)
<class '_cython_3_0_7.cython_function_or_method'>
sage: sage.misc.session.CythonFunctionType
<class '_cython_3_0_6.cython_function_or_method'>
sage: type(g) == sage.misc.session.CythonFunctionType
False

IOW, sagemath was built with cython 3.0.6; later cython was updated to 3.0.7.

Maybe this can be fixed by changing, in src/sage/misc/session.pyx, the line

CythonFunctionType = type(lambda: None)

by something like

CythonFunctionType = type(cython_lambda([], None))

Maybe better, use a test as in src/sage/misc/abstract_method.py, namely:

getattr(type(f), '__name__', None) == 'cython_function_or_method')

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions