diff --git a/sot/opcode_translator/executor/variables/base.py b/sot/opcode_translator/executor/variables/base.py index c672133ff..397c919ef 100644 --- a/sot/opcode_translator/executor/variables/base.py +++ b/sot/opcode_translator/executor/variables/base.py @@ -228,6 +228,7 @@ class VariableBase: """ tracker: Tracker # An attribute to store the Tracker object associated with the variable + value: Any name_generator = NameGenerator( "object_" ) # A class-level attribute to generate names for new variables diff --git a/sot/opcode_translator/executor/variables/iter.py b/sot/opcode_translator/executor/variables/iter.py index 9b1aa1c0d..0dd7c263c 100644 --- a/sot/opcode_translator/executor/variables/iter.py +++ b/sot/opcode_translator/executor/variables/iter.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING, Any, Sized from ..tracker import ConstTracker, DummyTracker from .base import VariableBase @@ -13,13 +13,18 @@ from ..tracker import Tracker +class SizedVariable(VariableBase, Sized): + def __len__(self) -> int: + ... + + class IterVariable(VariableBase): """ This Variable (include subclasses) should be generated only when simulate GET_ITER opcode """ def __init__( - self, obj: VariableBase, graph: FunctionGraph, tracker: Tracker + self, obj: SizedVariable, graph: FunctionGraph, tracker: Tracker ): super().__init__(graph, tracker) self.hold = obj @@ -94,7 +99,7 @@ def get_wrapped_items(self): return self.get_items() @staticmethod - def from_iterator(value, graph: FunctionGraph | None, tracker: Tracker): + def from_iterator(value, graph: FunctionGraph, tracker: Tracker): # breakpoint() if isinstance( value,