@@ -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,10 +1604,20 @@ 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 (
1589- f"Operand '{ operand } '" , operand , str , int , float , Variable , Rule
1612+ f"Operand '{ operand } '" ,
1613+ operand ,
1614+ str ,
1615+ int ,
1616+ float ,
1617+ Variable ,
1618+ Rule ,
1619+ "upper-scoped Variable" ,
1620+ "upper-scoped Rule" ,
15901621 )
15911622 )
15921623 if not name :
@@ -1602,6 +1633,10 @@ def __repr__(self):
16021633 self .write (writer )
16031634 return str (stream .getvalue (), encoding = "utf8" , errors = "replace" )
16041635
1636+ def upper_scope (self ):
1637+ """Adds the '.' upper-scope prefix to the serialization of the operand."""
1638+ return _ScopedOperand (self )
1639+
16051640 def copy (self ):
16061641 """Copies this rule instance
16071642
@@ -1640,6 +1675,7 @@ def write(self, writer):
16401675 writer .write (f'"{ operand } "' )
16411676 elif isinstance (operand , float ) and not math .isfinite (operand ):
16421677 writer .write ("#Missing" )
1678+ # int, finite float or _ScopedOperand cases
16431679 else :
16441680 writer .write (str (operand ))
16451681 if i < len (self .operands ) - 1 :
0 commit comments