#516 Fix order of requirements in decision
Closed 4 years ago by lholecek. Opened 4 years ago by lholecek.
lholecek/greenwave fix-requirements-order  into  master

Fix order of requirements in decision
Lukas Holecek • 4 years ago  
file modified
+1 -4
@@ -8,7 +8,7 @@ 

  import greenwave.resources

  from werkzeug.exceptions import BadRequest

  from flask import current_app

- from greenwave.utils import remove_duplicates, to_hashable

+ from greenwave.utils import remove_duplicates

  from greenwave.safe_yaml import (

      SafeYAMLBool,

      SafeYAMLChoice,
@@ -69,9 +69,6 @@ 

          """

          raise NotImplementedError()

  

-     def __hash__(self):

-         return hash(to_hashable(self.to_json()))

- 

      def __eq__(self, other):

          try:

              json1 = self.to_json()

file modified
+9 -14
@@ -145,18 +145,13 @@ 

  

  def remove_duplicates(func):

      def wrapper(*args, **kwargs):

-         rv = func(*args, **kwargs)

-         if isinstance(rv, list) and len(rv):

-             rv = list(set(rv))

just change set to dict.fromkeys

-         return rv

+         value = func(*args, **kwargs)

+         if not isinstance(value, list):

+             return value

+ 

+         unique = []

+         for item in value:

+             if item not in unique:

+                 unique.append(item)

+         return unique

      return wrapper

- 

- 

- def to_hashable(val):

-     if isinstance(val, list) or isinstance(val, tuple):

-         return tuple([to_hashable(v) for v in val])

-     if isinstance(val, dict):

-         return tuple([(k, to_hashable(val[k])) for k in sorted(val.keys())])

-     if isinstance(val, set):

-         return tuple(sorted(val))

-     return val

just change set to dict.fromkeys

OK, dropping this in favor of #517.

Pull-Request has been closed by lholecek

4 years ago