# Copyright 2018 D-Wave Systems Inc.
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#
# ================================================================================================

import sys
import inspect

from collections import namedtuple

_PY2 = sys.version_info.major == 2

if _PY2:

    def getargspec(f):
        return inspect.getargspec(f)

else:

    _ArgSpec = namedtuple('ArgSpec', ('args', 'varargs', 'keywords', 'defaults'))

    def getargspec(f):
        argspec = inspect.getfullargspec(f)
        # FullArgSpec(args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations)

        return _ArgSpec(argspec.args, argspec.varargs, argspec.varkw, argspec.defaults)

@@ -732,16 +732,106 @@
 nspect%0A%0A
+try:%0A    import collections.abc as abc%0Aexcept ImportError:%0A    import collections as abc%0A%0A
 from col
@@ -965,16 +965,58 @@
 pec(f)%0A%0A
+    def SortKey(obj):%0A        return obj%0A%0A
 else:%0A%0A 
@@ -1260,16 +1260,16 @@
 tions)%0A%0A
-
         
@@ -1348,8 +1348,817 @@
 faults)%0A
+%0A    # Based on an answer https://stackoverflow.com/a/34757114/8766655%0A    # by kindall https://stackoverflow.com/users/416467/kindall%0A    class SortKey(object):%0A        def __init__(self, obj):%0A            self.obj = obj%0A%0A        def __lt__(self, other):%0A            try:%0A                return self.obj %3C other.obj%0A            except TypeError:%0A                pass%0A%0A            if isinstance(self.obj, type(other.obj)):%0A                if not isinstance(self.obj, abc.Sequence):%0A                    raise TypeError(%22cannot compare types%22)%0A                for v0, v1 in zip(self.obj, other.obj):%0A                    if SortKey(v0) %3C SortKey(v1):%0A                        return True%0A                return len(self.obj) %3C len(other.obj)%0A%0A            return type(self.obj).__name__ %3C type(other.obj).__name__%0A

Support python2-like sorting in python3