gems-uff / noworkflow

Supporting infrastructure to run scientific experiments without a scientific workflow management system.
http://gems-uff.github.io/noworkflow
MIT License
120 stars 28 forks source link

ClassDef with bases results in RuntimeError #162

Open JoshuaGlaZ opened 4 months ago

JoshuaGlaZ commented 4 months ago

When processing a class with inheritance in noworkflow, the bases and keywords are not correctly captured, resulting in a RuntimeError for super(). ClassDef (class_def) without base classes are working, as do the name, body, and decorator lists of the class. However, the bases and keyword arguments are not captured correctly.

class BaseClass:
    def __init__(self, base_value):
        self.base_value = base_value

    def base_method(self):
        return "This is a method in the base class"

def class_decorator(cls):
    cls.decorated = True
    return cls

def method_decorator(func):
    def wrapper(*args, **kwargs):
        print("Method is being called")
        return func(*args, **kwargs)
    return wrapper

@class_decorator
class DerivedClass(BaseClass):
    class_variable = "I am a class variable"

    def __init__(self, base_value, derived_value):
        super().__init__(base_value)
        self.derived_value = derived_value

    @method_decorator
    def decorated_method(self):
        return "This method is decorated"

derived_instance = DerivedClass(10, 20)

Error Output:

[now] RuntimeError('super(): class cell not found') the execution finished with an uncaught exception. Traceback (most recent call last): File "...\noworkflow\capture\noworkflow\now\collection\prov_execution\execution.py", line 64, in collect_provenance exec(compiled, metascript.namespace) # pylint: disable=exec-used ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "...\noworkflow\demo_1\class.py", line 35, in derived_instance = DerivedClass(10, 20) ^^^^^^^^^^^^^^^^^^^^ File "...\noworkflow\capture\noworkflow\now\collection\prov_execution\collector.py", line 1207, in _call result = future.func(*args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "...\noworkflow\capture\noworkflow\now\collection\prov_execution\collector.py", line 1351, in new_function_def result = _call(*args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^ File "...\noworkflow\capture\noworkflow\now\collection\prov_execution\collector.py", line 1207, in _call result = future.func(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "...\noworkflow\capture\noworkflow\now\collection\prov_execution\collector.py", line 1370, in new_function_def result = function_def( ^^^^^^^^^^^^^ File "...\noworkflow\demo_1\class.py", line 27, in init super().init(base_value) ^^^^^^^ File "...\noworkflow\capture\noworkflow\now\collection\prov_execution\collector.py", line 1207, in _call result = future.func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RuntimeError: super(): class cell not found