[tune] Improve BOHB/ConfigSpace dependency check
diff --git a/python/ray/tune/suggest/bohb.py b/python/ray/tune/suggest/bohb.py
index 995c0f86f23ff..bef5b9ed3defa 100644
--- a/python/ray/tune/suggest/bohb.py
+++ b/python/ray/tune/suggest/bohb.py
@@ -5,7 +5,6 @@
 import math
 from typing import Dict, List, Optional, Union
 
-import ConfigSpace
 from ray.tune.result import DEFAULT_METRIC
 from ray.tune.sample import Categorical, Domain, Float, Integer, LogUniform, \
     Normal, \
@@ -17,6 +16,12 @@
 from ray.tune.suggest.variant_generator import parse_spec_vars
 from ray.tune.utils.util import flatten_dict, unflatten_list_dict
 
+try:
+    import ConfigSpace
+    from hpbandster.optimizers.config_generators.bohb import BOHB
+except ImportError:
+    BOHB = ConfigSpace = None
+
 logger = logging.getLogger(__name__)
 
 
@@ -105,15 +110,14 @@ class TuneBOHB(Searcher):
     """
 
     def __init__(self,
-                 space: Optional[Union[Dict,
-                                       ConfigSpace.ConfigurationSpace]] = None,
+                 space: Optional[Union[
+                     Dict, "ConfigSpace.ConfigurationSpace"]] = None,
                  bohb_config: Optional[Dict] = None,
                  max_concurrent: int = 10,
                  metric: Optional[str] = None,
                  mode: Optional[str] = None,
                  points_to_evaluate: Optional[List[Dict]] = None,
                  seed: Optional[int] = None):
-        from hpbandster.optimizers.config_generators.bohb import BOHB
         assert BOHB is not None, """HpBandSter must be installed!
             You can install HpBandSter with the command:
             `pip install hpbandster ConfigSpace`."""
@@ -236,7 +240,7 @@ def on_unpause(self, trial_id: str):
         self.running.add(trial_id)
 
     @staticmethod
-    def convert_search_space(spec: Dict) -> ConfigSpace.ConfigurationSpace:
+    def convert_search_space(spec: Dict) -> "ConfigSpace.ConfigurationSpace":
         resolved_vars, domain_vars, grid_vars = parse_spec_vars(spec)
 
         if grid_vars:

<!-- Thank you for your contribution! Please review https://github.com/ray-project/ray/blob/master/CONTRIBUTING.rst before opening a pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. -->

## Why are these changes needed?

Remove hard dependency for ConfigSpace on BOHB import

## Related issue number

https://github.com/ray-project/tune-sklearn/pull/198

## Checks

- [ ] I've run `scripts/format.sh` to lint the changes in this PR.
- [ ] I've included any doc changes needed for https://docs.ray.io/en/master/.
- [ ] I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [ ] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(
