Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Sage is not updating modules imported by an attached file

My file structure looks like:

project/
    __init__.py
    project.py
    bounds.py

project.py looks approximately like:

import sys
import os

import bounds

def myfunction(g):
    if has_bound(g):
        ...

def has_bound(g):
    lbound = 1
    for name, obj in inspect.getmembers(bounds, inspect.isclass):
        if obj.__module__ == 'bounds':
            new_bound = obj.bound(g)
            if new_bound > lbound:
                lbound = new_bound
    return lbound

bounds.py:

import abc

class BoundBase(object):
    @staticmethod
    @abc.abstractmethod
    def bound(g):
        return

class SpecificBound(LowerBoundBase):
    @staticmethod
    def bound(g):
        return 5

Now, I start a Sage session in the Terminal and do attach project.py. I can even make changes in project.py and see the results immediately in Sage. The problem is that if I change something in bounds.py, Sage won't pick up on the changes. I've tried combinations of reset(), detach(), attach(), load(), but the only thing that works is quitting Sage completely and restarting it. There must be a better way!