Skip to content

Commit

Permalink
Convert Union[a, b] to a | b
Browse files Browse the repository at this point in the history
This is allowed with `from __future__ import annotations`
  • Loading branch information
mhostetter committed Sep 11, 2022
1 parent 79655f2 commit a9a765e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 45 deletions.
6 changes: 3 additions & 3 deletions src/galois/_codes/_bch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from __future__ import annotations

import math
from typing import Tuple, List, Optional, Union, Type, overload
from typing import Tuple, List, Optional, Type, overload
from typing_extensions import Literal

import numba
Expand Down Expand Up @@ -420,7 +420,7 @@ def encode(self, message: ArrayLike, parity_only: bool = False) -> GF2:
codeword = message @ self.G
return codeword

def detect(self, codeword: ArrayLike) -> Union[np.bool_, np.ndarray]:
def detect(self, codeword: ArrayLike) -> np.bool_ | np.ndarray:
r"""
Detects if errors are present in the BCH codeword :math:`\mathbf{c}`.
Expand Down Expand Up @@ -577,7 +577,7 @@ def detect(self, codeword: ArrayLike) -> Union[np.bool_, np.ndarray]:
def decode(self, codeword: ArrayLike, errors: Literal[False] = False) -> GF2:
...
@overload
def decode(self, codeword: ArrayLike, errors: Literal[True]) -> Tuple[GF2, Union[np.integer, np.ndarray]]:
def decode(self, codeword: ArrayLike, errors: Literal[True]) -> Tuple[GF2, np.integer | np.ndarray]:
...
def decode(self, codeword, errors=False):
r"""
Expand Down
6 changes: 3 additions & 3 deletions src/galois/_codes/_reed_solomon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from __future__ import annotations

from typing import Tuple, Optional, Union, Type, overload
from typing import Tuple, Optional, Type, overload
from typing_extensions import Literal

import numba
Expand Down Expand Up @@ -307,7 +307,7 @@ def encode(self, message: ArrayLike, parity_only: bool = False) -> FieldArray:
codeword = message @ self.G
return codeword

def detect(self, codeword: ArrayLike) -> Union[np.bool_, np.ndarray]:
def detect(self, codeword: ArrayLike) -> np.bool_ | np.ndarray:
r"""
Detects if errors are present in the Reed-Solomon codeword :math:`\mathbf{c}`.
Expand Down Expand Up @@ -466,7 +466,7 @@ def detect(self, codeword: ArrayLike) -> Union[np.bool_, np.ndarray]:
def decode(self, codeword: ArrayLike, errors: Literal[False] = False) -> FieldArray:
...
@overload
def decode(self, codeword: ArrayLike, errors: Literal[True]) -> Tuple[FieldArray, Union[np.integer, np.ndarray]]:
def decode(self, codeword: ArrayLike, errors: Literal[True]) -> Tuple[FieldArray, np.integer | np.ndarray]:
...
def decode(self, codeword, errors=False):
r"""
Expand Down
8 changes: 4 additions & 4 deletions src/galois/_domains/_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import abc
import contextlib
import random
from typing import Optional, Union, Generator
from typing import Optional, Generator
from typing_extensions import Literal

import numpy as np
Expand Down Expand Up @@ -34,7 +34,7 @@ class Array(LinalgFunctionMixin, FunctionMixin, UFuncMixin, np.ndarray, metaclas

def __new__(
cls,
x: Union[ElementLike, ArrayLike],
x: ElementLike | ArrayLike,
dtype: Optional[DTypeLike] = None,
copy: bool = True,
order: Literal["K", "A", "C", "F"] = "K",
Expand Down Expand Up @@ -70,7 +70,7 @@ def _get_dtype(cls, dtype: DTypeLike) -> np.dtype:

@classmethod
@abc.abstractmethod
def _verify_array_like_types_and_values(cls, x: Union[ElementLike, ArrayLike]) -> Union[ElementLike, ArrayLike]:
def _verify_array_like_types_and_values(cls, x: ElementLike | ArrayLike) -> ElementLike | ArrayLike:
"""
Verify the types of the array-like object. Also verify the values of the array are within the range [0, order).
"""
Expand Down Expand Up @@ -237,7 +237,7 @@ def Random(
shape: ShapeLike = (),
low: ElementLike = 0,
high: Optional[ElementLike] = None,
seed: Optional[Union[int, np.random.Generator]] = None,
seed: Optional[int | np.random.Generator] = None,
dtype: Optional[DTypeLike] = None
) -> Array:
"""
Expand Down
18 changes: 9 additions & 9 deletions src/galois/_fields/_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from __future__ import annotations

from typing import Tuple, Optional, Union
from typing import Tuple, Optional
from typing_extensions import Literal

import numpy as np
Expand Down Expand Up @@ -55,7 +55,7 @@ class FieldArray(Array, metaclass=FieldArrayMeta):

def __new__(
cls,
x: Union[ElementLike, ArrayLike],
x: ElementLike | ArrayLike,
dtype: Optional[DTypeLike] = None,
copy: bool = True,
order: Literal["K", "A", "C", "F"] = "K",
Expand All @@ -67,7 +67,7 @@ def __new__(

def __init__(
self,
x: Union[ElementLike, ArrayLike],
x: ElementLike | ArrayLike,
dtype: Optional[DTypeLike] = None,
copy: bool = True,
order: Literal["K", "A", "C", "F"] = "K",
Expand Down Expand Up @@ -99,7 +99,7 @@ def __init__(
###############################################################################

@classmethod
def _verify_array_like_types_and_values(cls, x: Union[ElementLike, ArrayLike]) -> Union[ElementLike, ArrayLike]:
def _verify_array_like_types_and_values(cls, x: ElementLike | ArrayLike) -> ElementLike | ArrayLike:
if isinstance(x, (int, np.integer)):
cls._verify_scalar_value(x)
elif isinstance(x, cls):
Expand Down Expand Up @@ -278,7 +278,7 @@ def Random(
shape: ShapeLike = (),
low: ElementLike = 0,
high: Optional[ElementLike] = None,
seed: Optional[Union[int, np.random.Generator]] = None,
seed: Optional[int | np.random.Generator] = None,
dtype: Optional[DTypeLike] = None
) -> FieldArray:
return super().Random(shape=shape, low=low, high=high, seed=seed, dtype=dtype)
Expand Down Expand Up @@ -764,7 +764,7 @@ def primitive_roots_of_unity(cls, n: int) -> FieldArray:
# Instance methods
###############################################################################

def additive_order(self) -> Union[np.integer, np.ndarray]:
def additive_order(self) -> np.integer | np.ndarray:
r"""
Computes the additive order of each element in :math:`x`.
Expand Down Expand Up @@ -804,7 +804,7 @@ def additive_order(self) -> Union[np.integer, np.ndarray]:

return order

def multiplicative_order(self) -> Union[np.integer, np.ndarray]:
def multiplicative_order(self) -> np.integer | np.ndarray:
r"""
Computes the multiplicative order :math:`\textrm{ord}(x)` of each element in :math:`x`.
Expand Down Expand Up @@ -870,7 +870,7 @@ def multiplicative_order(self) -> Union[np.integer, np.ndarray]:

return order

def is_square(self) -> Union[np.bool_, np.ndarray]:
def is_square(self) -> np.bool_ | np.ndarray:
r"""
Determines if the elements of :math:`x` are squares in the finite field.
Expand Down Expand Up @@ -1501,7 +1501,7 @@ def minimal_poly(self) -> Poly:
else:
raise ValueError(f"The array must be either 0-D to return the minimal polynomial of a single element or 2-D to return the minimal polynomial of a square matrix, not have shape {self.shape}.")

def log(self, base: Optional[Union[ElementLike, ArrayLike]] = None) -> np.ndarray:
def log(self, base: Optional[ElementLike | ArrayLike] = None) -> np.ndarray:
r"""
Computes the logarithm of the array :math:`x` base :math:`\beta`.
Expand Down
6 changes: 3 additions & 3 deletions src/galois/_fields/_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import sys
import types
from typing import Union, Optional, Type
from typing import Optional, Type
from typing_extensions import Literal

from .._helper import export, verify_isinstance
Expand All @@ -24,7 +24,7 @@
def GF(
order: int,
irreducible_poly: Optional[PolyLike] = None,
primitive_element: Optional[Union[int, PolyLike]] = None, # pylint: disable=redefined-outer-name
primitive_element: Optional[int | PolyLike] = None, # pylint: disable=redefined-outer-name
verify: bool = True,
compile: Optional[Literal["auto", "jit-lookup", "jit-calculate", "python-calculate"]] = None, # pylint: disable=redefined-builtin
display: Optional[Literal["int", "poly", "power"]] = None
Expand Down Expand Up @@ -223,7 +223,7 @@ def GF(
def Field(
order: int,
irreducible_poly: Optional[PolyLike] = None,
primitive_element: Optional[Union[int, PolyLike]] = None, # pylint: disable=redefined-outer-name
primitive_element: Optional[int | PolyLike] = None, # pylint: disable=redefined-outer-name
verify: bool = True,
compile: Optional[Literal["auto", "jit-lookup", "jit-calculate", "python-calculate"]] = None, # pylint: disable=redefined-builtin
display: Optional[Literal["int", "poly", "power"]] = None
Expand Down
Loading

0 comments on commit a9a765e

Please sign in to comment.