Skip to content

Commit

Permalink
Wait on using typing.Self until Python >= 3.11
Browse files Browse the repository at this point in the history
Signed-off-by: Håkon Wiik Ånes <[email protected]>
  • Loading branch information
hakonanes committed Oct 5, 2024
1 parent f8e56f0 commit 4ab1d6f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/kikuchipy/detectors/ebsd_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import logging
from pathlib import Path
import re
from typing import TYPE_CHECKING, Self
from typing import TYPE_CHECKING

from diffsims.crystallography import ReciprocalLatticeVector
from matplotlib.figure import Figure
Expand Down Expand Up @@ -495,7 +495,7 @@ def r_max(self) -> np.ndarray:
return np.atleast_2d(np.sqrt(np.max(corners, axis=-1)))

@classmethod
def load(cls, fname: Path | str) -> Self:
def load(cls, fname: Path | str) -> EBSDDetector:
"""Return an EBSD detector loaded from a text file saved with
:meth:`save`.
Expand Down Expand Up @@ -557,7 +557,7 @@ def load(cls, fname: Path | str) -> Self:

return cls(pc=pc, **detector_kw)

def crop(self, extent: tuple[int, int, int, int] | list[int]) -> Self:
def crop(self, extent: tuple[int, int, int, int] | list[int]) -> EBSDDetector:
"""Return a new detector with its :attr:`shape` cropped and
:attr:`pc` values updated accordingly.
Expand Down Expand Up @@ -622,7 +622,7 @@ def crop(self, extent: tuple[int, int, int, int] | list[int]) -> Self:
azimuthal=self.azimuthal,
)

def deepcopy(self) -> Self:
def deepcopy(self) -> EBSDDetector:
"""Return a deep copy using :func:`copy.deepcopy`.
Returns
Expand Down Expand Up @@ -852,7 +852,7 @@ def extrapolate_pc(
px_size: float | None = None,
binning: int | None = None,
is_outlier: tuple | list | np.ndarray | None = None,
) -> Self:
) -> EBSDDetector:
r"""Return a new detector with projection centers (PCs) in a 2D
map extrapolated from an average PC.
Expand Down Expand Up @@ -959,7 +959,7 @@ def fit_pc(
plot: bool = True,
return_figure: bool = False,
figure_kwargs: dict | None = None,
) -> Self | tuple[EBSDDetector, Figure]:
) -> EBSDDetector | tuple[EBSDDetector, Figure]:
"""Return a new detector with interpolated projection centers
(PCs) for all points in a map by fitting a plane to :attr:`pc`
:cite:`winkelmann2020refined`.
Expand Down
8 changes: 5 additions & 3 deletions src/kikuchipy/filters/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
# You should have received a copy of the GNU General Public License
# along with kikuchipy. If not, see <http://www.gnu.org/licenses/>.

from __future__ import annotations

from copy import copy
from typing import Self, Sequence
from typing import Sequence

from dask.array import Array
import matplotlib.figure as mfigure
Expand Down Expand Up @@ -117,7 +119,7 @@ def __new__(
window: str | np.ndarray | Array | None = None,
shape: Sequence[int] | None = None,
**kwargs,
) -> Self:
) -> Window:
if window is None:
window = "circular"

Expand Down Expand Up @@ -197,7 +199,7 @@ def __array_finalize__(self, obj: Self | None) -> None:
self._name = getattr(obj, "_name", None)
self._circular = getattr(obj, "_circular", False)

def __array_wrap__(self, obj: Self) -> Self | np.ndarray:
def __array_wrap__(self, obj: Self) -> Window | np.ndarray:
if obj.shape == ():
return obj[()]
else:
Expand Down

0 comments on commit 4ab1d6f

Please sign in to comment.