prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Use function annotation syntax for Type Hints.
  After dropping Python 2.7 support at #710, we can define type hints with function annotation syntax. 
  ~~Do you have a plan to update the coding style guideline?~~
  https://github.com/optuna/optuna/wiki/Coding-Style-Conventions
  
  ## Progress
  
  - [x] `optuna/integration/sklearn.py` (#1735)
  - [x] `optuna/study.py` - assigned to harpy
  
  ## Note to the questioner
  
  We still cannot use variable annotation syntax introduced by [PEP 526](https://www.python.org/dev/peps/pep-0526/) because we supports Python 3.5.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `optuna/samplers/_random.py`
  Content:
  ```
  1 import numpy
  2 
  3 from optuna import distributions
  4 from optuna.samplers import BaseSampler
  5 from optuna import type_checking
  6 
  7 if type_checking.TYPE_CHECKING:
  8     from typing import Any  # NOQA
  9     from typing import Dict  # NOQA
  10     from typing import Optional  # NOQA
  11 
  12     from optuna.distributions import BaseDistribution  # NOQA
  13     from optuna.study import Study  # NOQA
  14     from optuna.trial import FrozenTrial  # NOQA
  15 
  16 
  17 class RandomSampler(BaseSampler):
  18     """Sampler using random sampling.
  19 
  20     This sampler is based on *independent sampling*.
  21     See also :class:`~optuna.samplers.BaseSampler` for more details of 'independent sampling'.
  22 
  23     Example:
  24 
  25         .. testcode::
  26 
  27             import optuna
  28             from optuna.samplers import RandomSampler
  29 
  30             def objective(trial):
  31                 x = trial.suggest_uniform('x', -5, 5)
  32                 return x**2
  33 
  34             study = optuna.create_study(sampler=RandomSampler())
  35             study.optimize(objective, n_trials=10)
  36 
  37         Args:
  38             seed: Seed for random number generator.
  39     """
  40 
  41     def __init__(self, seed=None):
  42         # type: (Optional[int]) -> None
  43 
  44         self._rng = numpy.random.RandomState(seed)
  45 
  46     def reseed_rng(self) -> None:
  47 
  48         self._rng = numpy.random.RandomState()
  49 
  50     def infer_relative_search_space(self, study, trial):
  51         # type: (Study, FrozenTrial) -> Dict[str, BaseDistribution]
  52 
  53         return {}
  54 
  55     def sample_relative(self, study, trial, search_space):
  56         # type: (Study, FrozenTrial, Dict[str, BaseDistribution]) -> Dict[str, Any]
  57 
  58         return {}
  59 
  60     def sample_independent(self, study, trial, param_name, param_distribution):
  61         # type: (Study, FrozenTrial, str, distributions.BaseDistribution) -> Any
  62 
  63         if isinstance(param_distribution, distributions.UniformDistribution):
  64             return self._rng.uniform(param_distribution.low, param_distribution.high)
  65         elif isinstance(param_distribution, distributions.LogUniformDistribution):
  66             log_low = numpy.log(param_distribution.low)
  67             log_high = numpy.log(param_distribution.high)
  68             return float(numpy.exp(self._rng.uniform(log_low, log_high)))
  69         elif isinstance(param_distribution, distributions.DiscreteUniformDistribution):
  70             q = param_distribution.q
  71             r = param_distribution.high - param_distribution.low
  72             # [low, high] is shifted to [0, r] to align sampled values at regular intervals.
  73             low = 0 - 0.5 * q
  74             high = r + 0.5 * q
  75             s = self._rng.uniform(low, high)
  76             v = numpy.round(s / q) * q + param_distribution.low
  77             # v may slightly exceed range due to round-off errors.
  78             return float(min(max(v, param_distribution.low), param_distribution.high))
  79         elif isinstance(param_distribution, distributions.IntUniformDistribution):
  80             # [low, high] is shifted to [0, r] to align sampled values at regular intervals.
  81             r = (param_distribution.high - param_distribution.low) / param_distribution.step
  82             # numpy.random.randint includes low but excludes high.
  83             s = self._rng.randint(0, r + 1)
  84             v = s * param_distribution.step + param_distribution.low
  85             return int(v)
  86         elif isinstance(param_distribution, distributions.IntLogUniformDistribution):
  87             log_low = numpy.log(param_distribution.low - 0.5)
  88             log_high = numpy.log(param_distribution.high + 0.5)
  89             s = numpy.exp(self._rng.uniform(log_low, log_high))
  90             v = numpy.round(s)
  91             return int(min(max(v, param_distribution.low), param_distribution.high))
  92         elif isinstance(param_distribution, distributions.CategoricalDistribution):
  93             choices = param_distribution.choices
  94             index = self._rng.randint(0, len(choices))
  95             return choices[index]
  96         else:
  97             raise NotImplementedError
  98
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/optuna/samplers/_random.py b/optuna/samplers/_random.py
  --- a/optuna/samplers/_random.py
  +++ b/optuna/samplers/_random.py
  @@ -1,17 +1,14 @@
  +from typing import Any
  +from typing import Dict
  +from typing import Optional
  +
   import numpy
   
   from optuna import distributions
  +from optuna.distributions import BaseDistribution
   from optuna.samplers import BaseSampler
  -from optuna import type_checking
  -
  -if type_checking.TYPE_CHECKING:
  -    from typing import Any  # NOQA
  -    from typing import Dict  # NOQA
  -    from typing import Optional  # NOQA
  -
  -    from optuna.distributions import BaseDistribution  # NOQA
  -    from optuna.study import Study  # NOQA
  -    from optuna.trial import FrozenTrial  # NOQA
  +from optuna.study import Study
  +from optuna.trial import FrozenTrial
   
   
   class RandomSampler(BaseSampler):
  @@ -38,8 +35,7 @@
               seed: Seed for random number generator.
       """
   
  -    def __init__(self, seed=None):
  -        # type: (Optional[int]) -> None
  +    def __init__(self, seed: Optional[int] = None) -> None:
   
           self._rng = numpy.random.RandomState(seed)
   
  @@ -47,18 +43,25 @@
   
           self._rng = numpy.random.RandomState()
   
  -    def infer_relative_search_space(self, study, trial):
  -        # type: (Study, FrozenTrial) -> Dict[str, BaseDistribution]
  +    def infer_relative_search_space(
  +        self, study: Study, trial: FrozenTrial
  +    ) -> Dict[str, BaseDistribution]:
   
           return {}
   
  -    def sample_relative(self, study, trial, search_space):
  -        # type: (Study, FrozenTrial, Dict[str, BaseDistribution]) -> Dict[str, Any]
  +    def sample_relative(
  +        self, study: Study, trial: FrozenTrial, search_space: Dict[str, BaseDistribution]
  +    ) -> Dict[str, Any]:
   
           return {}
   
  -    def sample_independent(self, study, trial, param_name, param_distribution):
  -        # type: (Study, FrozenTrial, str, distributions.BaseDistribution) -> Any
  +    def sample_independent(
  +        self,
  +        study: Study,
  +        trial: FrozenTrial,
  +        param_name: str,
  +        param_distribution: distributions.BaseDistribution,
  +    ) -> Any:
   
           if isinstance(param_distribution, distributions.UniformDistribution):
               return self._rng.uniform(param_distribution.low, param_distribution.high)
  
verification_info: {"golden_diff": "diff --git a/optuna/samplers/_random.py b/optuna/samplers/_random.py\n--- a/optuna/samplers/_random.py\n+++ b/optuna/samplers/_random.py\n@@ -1,17 +1,14 @@\n+from typing import Any\n+from typing import Dict\n+from typing import Optional\n+\n import numpy\n \n from optuna import distributions\n+from optuna.distributions import BaseDistribution\n from optuna.samplers import BaseSampler\n-from optuna import type_checking\n-\n-if type_checking.TYPE_CHECKING:\n-    from typing import Any  # NOQA\n-    from typing import Dict  # NOQA\n-    from typing import Optional  # NOQA\n-\n-    from optuna.distributions import BaseDistribution  # NOQA\n-    from optuna.study import Study  # NOQA\n-    from optuna.trial import FrozenTrial  # NOQA\n+from optuna.study import Study\n+from optuna.trial import FrozenTrial\n \n \n class RandomSampler(BaseSampler):\n@@ -38,8 +35,7 @@\n             seed: Seed for random number generator.\n     \"\"\"\n \n-    def __init__(self, seed=None):\n-        # type: (Optional[int]) -> None\n+    def __init__(self, seed: Optional[int] = None) -> None:\n \n         self._rng = numpy.random.RandomState(seed)\n \n@@ -47,18 +43,25 @@\n \n         self._rng = numpy.random.RandomState()\n \n-    def infer_relative_search_space(self, study, trial):\n-        # type: (Study, FrozenTrial) -> Dict[str, BaseDistribution]\n+    def infer_relative_search_space(\n+        self, study: Study, trial: FrozenTrial\n+    ) -> Dict[str, BaseDistribution]:\n \n         return {}\n \n-    def sample_relative(self, study, trial, search_space):\n-        # type: (Study, FrozenTrial, Dict[str, BaseDistribution]) -> Dict[str, Any]\n+    def sample_relative(\n+        self, study: Study, trial: FrozenTrial, search_space: Dict[str, BaseDistribution]\n+    ) -> Dict[str, Any]:\n \n         return {}\n \n-    def sample_independent(self, study, trial, param_name, param_distribution):\n-        # type: (Study, FrozenTrial, str, distributions.BaseDistribution) -> Any\n+    def sample_independent(\n+        self,\n+        study: Study,\n+        trial: FrozenTrial,\n+        param_name: str,\n+        param_distribution: distributions.BaseDistribution,\n+    ) -> Any:\n \n         if isinstance(param_distribution, distributions.UniformDistribution):\n             return self._rng.uniform(param_distribution.low, param_distribution.high)\n", "issue": "Use function annotation syntax for Type Hints.\nAfter dropping Python 2.7 support at #710, we can define type hints with function annotation syntax. \r\n~~Do you have a plan to update the coding style guideline?~~\r\nhttps://github.com/optuna/optuna/wiki/Coding-Style-Conventions\r\n\r\n## Progress\r\n\r\n- [x] `optuna/integration/sklearn.py` (#1735)\r\n- [x] `optuna/study.py` - assigned to harpy\r\n\r\n## Note to the questioner\r\n\r\nWe still cannot use variable annotation syntax introduced by [PEP 526](https://www.python.org/dev/peps/pep-0526/) because we supports Python 3.5.\n", "before_files": [{"content": "import numpy\n\nfrom optuna import distributions\nfrom optuna.samplers import BaseSampler\nfrom optuna import type_checking\n\nif type_checking.TYPE_CHECKING:\n    from typing import Any  # NOQA\n    from typing import Dict  # NOQA\n    from typing import Optional  # NOQA\n\n    from optuna.distributions import BaseDistribution  # NOQA\n    from optuna.study import Study  # NOQA\n    from optuna.trial import FrozenTrial  # NOQA\n\n\nclass RandomSampler(BaseSampler):\n    \"\"\"Sampler using random sampling.\n\n    This sampler is based on *independent sampling*.\n    See also :class:`~optuna.samplers.BaseSampler` for more details of 'independent sampling'.\n\n    Example:\n\n        .. testcode::\n\n            import optuna\n            from optuna.samplers import RandomSampler\n\n            def objective(trial):\n                x = trial.suggest_uniform('x', -5, 5)\n                return x**2\n\n            study = optuna.create_study(sampler=RandomSampler())\n            study.optimize(objective, n_trials=10)\n\n        Args:\n            seed: Seed for random number generator.\n    \"\"\"\n\n    def __init__(self, seed=None):\n        # type: (Optional[int]) -> None\n\n        self._rng = numpy.random.RandomState(seed)\n\n    def reseed_rng(self) -> None:\n\n        self._rng = numpy.random.RandomState()\n\n    def infer_relative_search_space(self, study, trial):\n        # type: (Study, FrozenTrial) -> Dict[str, BaseDistribution]\n\n        return {}\n\n    def sample_relative(self, study, trial, search_space):\n        # type: (Study, FrozenTrial, Dict[str, BaseDistribution]) -> Dict[str, Any]\n\n        return {}\n\n    def sample_independent(self, study, trial, param_name, param_distribution):\n        # type: (Study, FrozenTrial, str, distributions.BaseDistribution) -> Any\n\n        if isinstance(param_distribution, distributions.UniformDistribution):\n            return self._rng.uniform(param_distribution.low, param_distribution.high)\n        elif isinstance(param_distribution, distributions.LogUniformDistribution):\n            log_low = numpy.log(param_distribution.low)\n            log_high = numpy.log(param_distribution.high)\n            return float(numpy.exp(self._rng.uniform(log_low, log_high)))\n        elif isinstance(param_distribution, distributions.DiscreteUniformDistribution):\n            q = param_distribution.q\n            r = param_distribution.high - param_distribution.low\n            # [low, high] is shifted to [0, r] to align sampled values at regular intervals.\n            low = 0 - 0.5 * q\n            high = r + 0.5 * q\n            s = self._rng.uniform(low, high)\n            v = numpy.round(s / q) * q + param_distribution.low\n            # v may slightly exceed range due to round-off errors.\n            return float(min(max(v, param_distribution.low), param_distribution.high))\n        elif isinstance(param_distribution, distributions.IntUniformDistribution):\n            # [low, high] is shifted to [0, r] to align sampled values at regular intervals.\n            r = (param_distribution.high - param_distribution.low) / param_distribution.step\n            # numpy.random.randint includes low but excludes high.\n            s = self._rng.randint(0, r + 1)\n            v = s * param_distribution.step + param_distribution.low\n            return int(v)\n        elif isinstance(param_distribution, distributions.IntLogUniformDistribution):\n            log_low = numpy.log(param_distribution.low - 0.5)\n            log_high = numpy.log(param_distribution.high + 0.5)\n            s = numpy.exp(self._rng.uniform(log_low, log_high))\n            v = numpy.round(s)\n            return int(min(max(v, param_distribution.low), param_distribution.high))\n        elif isinstance(param_distribution, distributions.CategoricalDistribution):\n            choices = param_distribution.choices\n            index = self._rng.randint(0, len(choices))\n            return choices[index]\n        else:\n            raise NotImplementedError\n", "path": "optuna/samplers/_random.py"}], "after_files": [{"content": "from typing import Any\nfrom typing import Dict\nfrom typing import Optional\n\nimport numpy\n\nfrom optuna import distributions\nfrom optuna.distributions import BaseDistribution\nfrom optuna.samplers import BaseSampler\nfrom optuna.study import Study\nfrom optuna.trial import FrozenTrial\n\n\nclass RandomSampler(BaseSampler):\n    \"\"\"Sampler using random sampling.\n\n    This sampler is based on *independent sampling*.\n    See also :class:`~optuna.samplers.BaseSampler` for more details of 'independent sampling'.\n\n    Example:\n\n        .. testcode::\n\n            import optuna\n            from optuna.samplers import RandomSampler\n\n            def objective(trial):\n                x = trial.suggest_uniform('x', -5, 5)\n                return x**2\n\n            study = optuna.create_study(sampler=RandomSampler())\n            study.optimize(objective, n_trials=10)\n\n        Args:\n            seed: Seed for random number generator.\n    \"\"\"\n\n    def __init__(self, seed: Optional[int] = None) -> None:\n\n        self._rng = numpy.random.RandomState(seed)\n\n    def reseed_rng(self) -> None:\n\n        self._rng = numpy.random.RandomState()\n\n    def infer_relative_search_space(\n        self, study: Study, trial: FrozenTrial\n    ) -> Dict[str, BaseDistribution]:\n\n        return {}\n\n    def sample_relative(\n        self, study: Study, trial: FrozenTrial, search_space: Dict[str, BaseDistribution]\n    ) -> Dict[str, Any]:\n\n        return {}\n\n    def sample_independent(\n        self,\n        study: Study,\n        trial: FrozenTrial,\n        param_name: str,\n        param_distribution: distributions.BaseDistribution,\n    ) -> Any:\n\n        if isinstance(param_distribution, distributions.UniformDistribution):\n            return self._rng.uniform(param_distribution.low, param_distribution.high)\n        elif isinstance(param_distribution, distributions.LogUniformDistribution):\n            log_low = numpy.log(param_distribution.low)\n            log_high = numpy.log(param_distribution.high)\n            return float(numpy.exp(self._rng.uniform(log_low, log_high)))\n        elif isinstance(param_distribution, distributions.DiscreteUniformDistribution):\n            q = param_distribution.q\n            r = param_distribution.high - param_distribution.low\n            # [low, high] is shifted to [0, r] to align sampled values at regular intervals.\n            low = 0 - 0.5 * q\n            high = r + 0.5 * q\n            s = self._rng.uniform(low, high)\n            v = numpy.round(s / q) * q + param_distribution.low\n            # v may slightly exceed range due to round-off errors.\n            return float(min(max(v, param_distribution.low), param_distribution.high))\n        elif isinstance(param_distribution, distributions.IntUniformDistribution):\n            # [low, high] is shifted to [0, r] to align sampled values at regular intervals.\n            r = (param_distribution.high - param_distribution.low) / param_distribution.step\n            # numpy.random.randint includes low but excludes high.\n            s = self._rng.randint(0, r + 1)\n            v = s * param_distribution.step + param_distribution.low\n            return int(v)\n        elif isinstance(param_distribution, distributions.IntLogUniformDistribution):\n            log_low = numpy.log(param_distribution.low - 0.5)\n            log_high = numpy.log(param_distribution.high + 0.5)\n            s = numpy.exp(self._rng.uniform(log_low, log_high))\n            v = numpy.round(s)\n            return int(min(max(v, param_distribution.low), param_distribution.high))\n        elif isinstance(param_distribution, distributions.CategoricalDistribution):\n            choices = param_distribution.choices\n            index = self._rng.randint(0, len(choices))\n            return choices[index]\n        else:\n            raise NotImplementedError\n", "path": "optuna/samplers/_random.py"}]}