1- import inspect
21import textwrap
32import types
43from typing import Type
@@ -16,63 +15,13 @@ def patch_pyomo():
1615 if _patched_pyomo :
1716 return
1817
19- # fix Pyomo issue #2019. Once PR #2020 gets released this will no longer be needed
20- from pyomo .core .base .misc import _robust_sort_keyfcn
21-
22- setattr (_robust_sort_keyfcn , "__call__" , fixed_robust_sort_keyfcn )
23-
2418 # Patch Set and Param to allow specifying input file location (via input_file="...")
2519 extend_to_allow_loading (Set )
2620 extend_to_allow_loading (Param )
2721
2822 _patched_pyomo = True
2923
3024
31- def fixed_robust_sort_keyfcn (self , val , use_key = True ):
32- """Generate a tuple ( str(type_name), val ) for sorting the value.
33-
34- `key=` expects a function. We are generating a functor so we
35- have a convenient place to store the _typemap, which converts
36- the type-specific functions for converting a value to the second
37- argument of the sort key.
38-
39- """
40- if use_key and self ._key is not None :
41- val = self ._key (val )
42-
43- try :
44- i , _typename = self ._typemap [val .__class__ ]
45- except KeyError :
46- # If this is not a type we have seen before, determine what
47- # to use for the second value in the tuple.
48- _type = val .__class__
49- _typename = _type .__name__
50- try :
51- # 1: Check if the type is comparable. In Python 3, sorted()
52- # uses "<" to compare objects.
53- val < val
54- i = 1
55- except :
56- try :
57- # 2: try converting the value to string
58- str (val )
59- i = 2
60- except :
61- # 3: fallback on id(). Not deterministic
62- # (run-to-run), but at least is consistent within
63- # this run.
64- i = 3
65- self ._typemap [_type ] = i , _typename
66- if i == 1 :
67- return _typename , val
68- elif i == 3 :
69- return _typename , tuple (self (v , use_key = False ) for v in val )
70- elif i == 2 :
71- return _typename , str (val )
72- else :
73- return _typename , id (val )
74-
75-
7625def extend_to_allow_loading (cls : Type ):
7726 def new_init (
7827 self , * args , input_file = None , input_column = None , input_optional = None , ** kwargs
0 commit comments