From e9d68068513f777ac9c038f2cb030ecb3636c9be Mon Sep 17 00:00:00 2001 From: mhostetter Date: Fri, 22 Apr 2022 17:32:17 -0400 Subject: [PATCH] Move placeholder factory functions into `_factory.py` --- galois/_domains/_array.py | 15 +-------------- galois/_domains/_factory.py | 20 ++++++++++++++++++++ galois/_polys/_irreducible.py | 2 +- galois/_polys/_poly.py | 3 ++- galois/_polys/_primitive.py | 2 +- 5 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 galois/_domains/_factory.py diff --git a/galois/_domains/_array.py b/galois/_domains/_array.py index 9a259a427..66113f1c6 100644 --- a/galois/_domains/_array.py +++ b/galois/_domains/_array.py @@ -5,7 +5,7 @@ import contextlib import random -from typing import Optional, Union, Type +from typing import Optional, Union from typing_extensions import Literal import numpy as np @@ -493,16 +493,3 @@ def astype(self, dtype, order="K", casting="unsafe", subok=True, copy=True): if dtype not in type(self)._dtypes: raise TypeError(f"{type(self)._name} arrays can only be cast as integer dtypes in {type(self)._dtypes}, not {dtype}.") return super().astype(dtype, order=order, casting=casting, subok=subok, copy=copy) - - -def FIELD_FACTORY(*args, **kwargs) -> Type[Array]: # pylint: disable=unused-argument - """ - This will be monkey-patched to be `galois.GF()` in __init__.py. - """ - return Array - - -DEFAULT_FIELD_ARRAY = Array -""" -This will be monkey-patched to be `galois.GF2` in __init__.py. -""" diff --git a/galois/_domains/_factory.py b/galois/_domains/_factory.py new file mode 100644 index 000000000..9e4909cfe --- /dev/null +++ b/galois/_domains/_factory.py @@ -0,0 +1,20 @@ +""" +A module for for creating Array subclasses. These functions are provided to prevent circular dependencies. +They will be monkey-patched into the _polys module. +""" +from typing import Type + +from ._array import Array + + +def FIELD_FACTORY(*args, **kwargs) -> Type[Array]: # pylint: disable=unused-argument + """ + This will be monkey-patched to be `galois.GF()` in __init__.py. + """ + return Array + + +DEFAULT_FIELD_ARRAY = Array +""" +This will be monkey-patched to be `galois.GF2` in __init__.py. +""" diff --git a/galois/_polys/_irreducible.py b/galois/_polys/_irreducible.py index 4f7d048d5..e73d3a3b1 100644 --- a/galois/_polys/_irreducible.py +++ b/galois/_polys/_irreducible.py @@ -8,7 +8,7 @@ import numpy as np -from .._domains._array import FIELD_FACTORY +from .._domains._factory import FIELD_FACTORY from .._overrides import set_module from .._prime import factors, is_prime_power diff --git a/galois/_polys/_poly.py b/galois/_polys/_poly.py index 0d7f3b28f..d9683a4d5 100644 --- a/galois/_polys/_poly.py +++ b/galois/_polys/_poly.py @@ -8,7 +8,8 @@ import numpy as np -from .._domains._array import Array, DEFAULT_FIELD_ARRAY +from .._domains import Array +from .._domains._factory import DEFAULT_FIELD_ARRAY from .._overrides import set_module from ..typing import ElementLike, ArrayLike, PolyLike diff --git a/galois/_polys/_primitive.py b/galois/_polys/_primitive.py index 8971c24eb..b5845d0f5 100644 --- a/galois/_polys/_primitive.py +++ b/galois/_polys/_primitive.py @@ -8,7 +8,7 @@ import numpy as np -from .._domains._array import FIELD_FACTORY +from .._domains._factory import FIELD_FACTORY from .._databases import ConwayPolyDatabase from .._overrides import set_module from .._prime import factors, is_prime, is_prime_power