util.py 945 B

1234567891011121314151617181920212223242526272829
  1. import logging
  2. from typing import Dict, Optional
  3. logger = logging.getLogger(__name__)
  4. def _set_search_properties_backwards_compatible(
  5. set_search_properties_func,
  6. metric: Optional[str],
  7. mode: Optional[str],
  8. config: Dict,
  9. **spec
  10. ) -> bool:
  11. """Wraps around set_search_properties() so that it is backward compatible.
  12. Also outputs a warning to encourage custom searchers to be updated.
  13. """
  14. try:
  15. return set_search_properties_func(metric, mode, config, **spec)
  16. except TypeError as e:
  17. if "set_search_properties() got an unexpected keyword argument" in str(e):
  18. logger.warning(
  19. "Please update custom Searcher to take in function signature "
  20. "as ``def set_search_properties(metric, mode, config, "
  21. "**spec) -> bool``."
  22. )
  23. return set_search_properties_func(metric, mode, config)
  24. else:
  25. raise e