@@ -1836,7 +1836,7 @@ def is_constructed(self):
18361836 return False
18371837 return True
18381838
1839- def _pprint_blockdata_components (self , ostream ):
1839+ def _pprint_blockdata_components (self , ostream , sort ):
18401840 #
18411841 # We hard-code the order of the core Pyomo modeling
18421842 # components, to ensure that the output follows the logical order
@@ -1862,15 +1862,18 @@ def _pprint_blockdata_components(self, ostream):
18621862
18631863 indented_ostream = StreamIndenter (ostream , self ._PPRINT_INDENT )
18641864 for item in items :
1865- keys = sorted (self .component_map (item ))
1865+ if SortComponents .ALPHABETICAL in sort :
1866+ keys = sorted (self .component_map (item ))
1867+ else :
1868+ keys = list (self .component_map (item ))
18661869 if not keys :
18671870 continue
18681871 #
18691872 # NOTE: these conditional checks should not be hard-coded.
18701873 #
18711874 ostream .write ("%d %s Declarations\n " % (len (keys ), item .__name__ ))
18721875 for key in keys :
1873- self .component (key ).pprint (ostream = indented_ostream )
1876+ self .component (key ).pprint (ostream = indented_ostream , sort = sort )
18741877 ostream .write ("\n " )
18751878 #
18761879 # Model Order
@@ -2070,17 +2073,17 @@ class Block(ActiveIndexedComponent):
20702073 _ComponentDataClass = BlockData
20712074 _private_data_initializers = defaultdict (lambda : dict )
20722075
2073- @overload
2074- def __new__ (
2075- cls : Type [Block ], * args , ** kwds
2076- ) -> Union [ScalarBlock , IndexedBlock ]: ...
2077-
20782076 @overload
20792077 def __new__ (cls : Type [ScalarBlock ], * args , ** kwds ) -> ScalarBlock : ...
20802078
20812079 @overload
20822080 def __new__ (cls : Type [IndexedBlock ], * args , ** kwds ) -> IndexedBlock : ...
20832081
2082+ @overload
2083+ def __new__ (
2084+ cls : Type [Block ], * args , ** kwds
2085+ ) -> Union [ScalarBlock , IndexedBlock ]: ...
2086+
20842087 def __new__ (cls , * args , ** kwds ):
20852088 if cls != Block :
20862089 return super (Block , cls ).__new__ (cls )
@@ -2237,25 +2240,26 @@ def construct(self, data=None):
22372240 _BlockConstruction .data .pop (id (self ), None )
22382241 timer .report ()
22392242
2240- def _pprint_callback (self , ostream , idx , data ):
2243+ def _pprint_callback (self , ostream , sort , idx , data ):
22412244 if not self .is_indexed ():
2242- data ._pprint_blockdata_components (ostream )
2245+ data ._pprint_blockdata_components (ostream , sort )
22432246 else :
22442247 ostream .write ("%s : Active=%s\n " % (data .name , data .active ))
22452248 ostream = StreamIndenter (ostream , self ._PPRINT_INDENT )
2246- data ._pprint_blockdata_components (ostream )
2249+ data ._pprint_blockdata_components (ostream , sort )
22472250
22482251 def _pprint (self ):
2249- _attrs = [
2250- ("Size" , len (self )),
2251- ("Index" , self ._index_set if self .is_indexed () else None ),
2252- ('Active' , self .active ),
2253- ]
22542252 # HACK: suppress the top-level block header (for historical reasons)
22552253 if self .parent_block () is None and not self .is_indexed ():
2256- return None , self . _data . items (), None , self . _pprint_callback
2254+ _attrs = None
22572255 else :
2258- return _attrs , self ._data .items (), None , self ._pprint_callback
2256+ _attrs = [
2257+ ("Size" , len (self )),
2258+ ("Index" , self ._index_set if self .is_indexed () else None ),
2259+ ('Active' , self .active ),
2260+ ]
2261+
2262+ return _attrs , self .items , None , self ._pprint_callback
22592263
22602264 def display (self , filename = None , ostream = None , prefix = "" ):
22612265 """
0 commit comments