Skip to content

Commit e2d90ac

Browse files
esantorellafacebook-github-bot
authored andcommitted
Use types.NoneType rather than defining NoneType in BoTorch (#2338)
Summary: Pull Request resolved: #2338 - Rremove BoTorch `NoneType` and replace its usages with `types.NoneType`, since as of Python 3.10, types.NoneType (once again) exists. - Use `None` or `Optional` for the purposes of type-hinting (and only for type-hinting) in place of `NoneType` since they are equivalent for type-hinting, although not in general. Reviewed By: saitcakmak Differential Revision: D57172472 fbshipit-source-id: b5be445caaf738ac8e227bd6595031c66f22d85e
1 parent 20db4d5 commit e2d90ac

File tree

4 files changed

+5
-7
lines changed

4 files changed

+5
-7
lines changed

botorch/optim/closures/model_closures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
from __future__ import annotations
1010

1111
from itertools import chain, repeat
12+
from types import NoneType
1213
from typing import Any, Callable, Dict, Optional, Sequence, Tuple
1314

1415
from botorch.optim.closures.core import ForwardBackwardClosure
1516
from botorch.utils.dispatcher import Dispatcher, type_bypassing_encoder
16-
from botorch.utils.types import NoneType
1717
from gpytorch.mlls import (
1818
ExactMarginalLogLikelihood,
1919
MarginalLogLikelihood,

botorch/optim/utils/numpy_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import numpy as np
1515
import torch
16-
from botorch.utils.types import NoneType
1716
from numpy import ndarray
1817
from torch import Tensor
1918

@@ -137,7 +136,7 @@ def set_tensors_from_ndarray_1d(
137136
def get_bounds_as_ndarray(
138137
parameters: Dict[str, Tensor],
139138
bounds: Dict[
140-
str, Tuple[Union[float, Tensor, NoneType], Union[float, Tensor, NoneType]]
139+
str, Tuple[Optional[Union[float, Tensor]], Optional[Union[float, Tensor]]]
141140
],
142141
) -> Optional[np.ndarray]:
143142
r"""Helper method for converting bounds into an ndarray.

botorch/sampling/pathwise/update_strategies.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from __future__ import annotations
88

9+
from types import NoneType
10+
911
from typing import Any, Callable, Optional, Union
1012

1113
import torch
@@ -20,7 +22,7 @@
2022
TInputTransform,
2123
)
2224
from botorch.utils.dispatcher import Dispatcher
23-
from botorch.utils.types import DEFAULT, NoneType
25+
from botorch.utils.types import DEFAULT
2426
from gpytorch.kernels.kernel import Kernel
2527
from gpytorch.likelihoods import _GaussianLikelihoodBase, Likelihood
2628
from gpytorch.models import ApproximateGP, ExactGP, GP

botorch/utils/types.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
from __future__ import annotations
88

99

10-
NoneType = type(None) # stop gap for the return of NoneType in 3.10
11-
12-
1310
class _DefaultType(type):
1411
r"""
1512
Private class whose sole instance `DEFAULT` is as a special indicator

0 commit comments

Comments
 (0)