@@ -81,6 +81,23 @@ def _quote_value(value):
8181 return quoted_value
8282
8383
84+ class _ScopedOperand :
85+ def __init__ (self , operand ):
86+ assert type (operand ) in (Variable , Rule ), type_error_message (
87+ "operand" , operand , Variable , Rule
88+ )
89+ self .operand = operand
90+
91+ def __repr__ (self ):
92+ stream = io .BytesIO ()
93+ writer = KhiopsOutputWriter (stream )
94+ if isinstance (self .operand , Variable ):
95+ writer .write (_format_name (self .operand .name ))
96+ else :
97+ self .operand .write (writer )
98+ return "." + str (stream .getvalue (), encoding = "utf8" , errors = "replace" )
99+
100+
84101class DictionaryDomain (KhiopsJSONObject ):
85102 """Main class containing the information of a Khiops dictionary file
86103
@@ -1206,6 +1223,10 @@ def __str__(self):
12061223 self .write (writer )
12071224 return str (stream .getvalue (), encoding = "utf8" , errors = "replace" )
12081225
1226+ def upper_scope (self ):
1227+ """Adds the '.' upper-scope prefix to the serialization of the operand."""
1228+ return _ScopedOperand (self )
1229+
12091230 def copy (self ):
12101231 """Copies this variable instance
12111232
@@ -1583,7 +1604,9 @@ def __init__(self, name, *operands):
15831604 if not isinstance (name , str ):
15841605 raise TypeError (type_error_message ("name" , name , str ))
15851606 for operand in operands :
1586- if not isinstance (operand , (str , int , float , Variable , Rule )):
1607+ if not isinstance (
1608+ operand , (str , int , float , Variable , Rule , _ScopedOperand )
1609+ ):
15871610 raise TypeError (
15881611 type_error_message (
15891612 f"Operand '{ operand } '" , operand , str , int , float , Variable , Rule
@@ -1602,6 +1625,10 @@ def __repr__(self):
16021625 self .write (writer )
16031626 return str (stream .getvalue (), encoding = "utf8" , errors = "replace" )
16041627
1628+ def upper_scope (self ):
1629+ """Adds the '.' upper-scope prefix to the serialization of the operand."""
1630+ return _ScopedOperand (self )
1631+
16051632 def copy (self ):
16061633 """Copies this rule instance
16071634
@@ -1640,6 +1667,7 @@ def write(self, writer):
16401667 writer .write (f'"{ operand } "' )
16411668 elif isinstance (operand , float ) and not math .isfinite (operand ):
16421669 writer .write ("#Missing" )
1670+ # int, finite float or _ScopedOperand cases
16431671 else :
16441672 writer .write (str (operand ))
16451673 if i < len (self .operands ) - 1 :
0 commit comments