Skip to content

Commit 020e8b2

Browse files
committed
chore: move Self to compat module
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 4c456fa commit 020e8b2

File tree

7 files changed

+26
-8
lines changed

7 files changed

+26
-8
lines changed

pyproject.toml

+7-2
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ extend-select = [
233233
"PT", # flake8-pytest-style
234234
"PTH", # flake8-use-pathlib
235235
"PYI", # flake8-pyi
236+
"TID251", # flake8-tidy-imports.banned-api
236237
"RET", # flake8-return
237238
"RUF", # Ruff-specific
238239
"SIM", # flake8-simplify
@@ -247,10 +248,13 @@ ignore = [
247248
"PT011", # pytest.raises too broad
248249
"PYI034", # We are returning Self, just generic
249250
]
250-
typing-modules = ["boost_histogram.typing"]
251+
typing-modules = ["boost_histogram._compat.typing"]
251252
isort.required-imports = ["from __future__ import annotations"]
252253
exclude = ["extern/*"]
253254

255+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
256+
"typing.Self".msg = "Use boost_histogram._compat.typing.Self instead."
257+
"typing_extensions.Self".msg = "Use boost_histogram._compat.typing.Self instead."
254258

255259
[tool.ruff.lint.mccabe]
256260
max-complexity = 13
@@ -261,7 +265,8 @@ max-complexity = 13
261265
"scripts/*" = ["T20"]
262266
"tests/*" = ["T20"]
263267
"notebooks/*" = ["T20"]
264-
"*.pyi" = ["F401"]
268+
"*.pyi" = ["F401", "TID251"]
265269
"docs/conf.py" = ["ARG001"]
266270
"src/boost_histogram/test.py" = ["PT"]
267271
"**.ipynb" = ["I002", "E731"]
272+
"src/boost_histogram/_compat/**.py" = ["TID251"]

src/boost_histogram/_compat/__init__.py

Whitespace-only changes.

src/boost_histogram/_compat/typing.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import sys
2+
import typing
3+
4+
if sys.version_info >= (3, 11):
5+
from typing import Self
6+
elif typing.TYPE_CHECKING:
7+
from typing_extensions import Self
8+
else:
9+
Self = object
10+
11+
__all__ = ["Self"]
12+
13+
def __dir__() -> list[str]:
14+
return __all__

src/boost_histogram/axis/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
)
1616

1717
import numpy as np # pylint: disable=unused-import
18-
from typing_extensions import Self
1918

2019
import boost_histogram
2120

21+
from .._compat.typing import Self
2222
from .._core import axis as ca
2323
from .._utils import cast, register, zip_strict
2424
from . import transform

src/boost_histogram/axis/transform.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
import copy
44
from typing import Any, ClassVar, TypeVar
55

6-
from typing_extensions import Self
7-
86
import boost_histogram
97

8+
from .._compat.typing import Self
109
from .._core import axis as ca
1110
from .._utils import register
1211

src/boost_histogram/histogram.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
)
2323

2424
import numpy as np
25-
from typing_extensions import Self
2625

2726
import boost_histogram
2827
from boost_histogram import _core
2928

29+
from ._compat.typing import Self
3030
from ._utils import cast, register
3131
from .axis import AxesTuple, Axis, Variable
3232
from .storage import Double, Storage
@@ -36,6 +36,7 @@
3636
if TYPE_CHECKING:
3737
from builtins import ellipsis
3838

39+
3940
try:
4041
from . import _core
4142
except ImportError as err:

src/boost_histogram/tag.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
if TYPE_CHECKING:
1313
from uhi.typing.plottable import PlottableAxis
1414

15-
from typing_extensions import Self
16-
15+
from ._compat.typing import Self
1716
from .typing import AxisLike
1817

1918
__all__ = ("Locator", "Slicer", "at", "loc", "overflow", "rebin", "sum", "underflow")

0 commit comments

Comments
 (0)