mirror of
https://github.com/p2p-ld/numpydantic.git
synced 2024-11-12 17:54:29 +00:00
lint and format nptyping
This commit is contained in:
parent
cbe5d33fd9
commit
dba550f41b
18 changed files with 43 additions and 32 deletions
10
src/numpydantic/vendor/__init__.py
vendored
10
src/numpydantic/vendor/__init__.py
vendored
|
@ -0,0 +1,10 @@
|
|||
"""
|
||||
Vendored modules - see licenses in /licenses.
|
||||
|
||||
Currently consists just of nptyping, as it is no longer maintained
|
||||
and pins a version of numpy<2, and we have to do an increasing
|
||||
number of awkward monkeypatches for perf and customization reasons.
|
||||
|
||||
This vendored module will slowly be worked out of the code and
|
||||
all its functionality replaced.
|
||||
"""
|
1
src/numpydantic/vendor/nptyping/__init__.py
vendored
1
src/numpydantic/vendor/nptyping/__init__.py
vendored
|
@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
from nptyping.assert_isinstance import assert_isinstance
|
||||
from nptyping.error import (
|
||||
InvalidArgumentsError,
|
||||
|
|
|
@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
from typing import (
|
||||
Any,
|
||||
Optional,
|
||||
|
|
|
@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from inspect import FrameInfo
|
||||
from typing import (
|
||||
|
@ -44,6 +45,7 @@ class InconstructableMeta(ABCMeta):
|
|||
"""
|
||||
|
||||
def __call__(cls, *_: Any, **__: Any) -> None:
|
||||
"""Raise an error if constructed"""
|
||||
raise NPTypingError(
|
||||
f"Cannot instantiate nptyping.{cls.__name__}. Did you mean to use [ ] ?"
|
||||
)
|
||||
|
@ -76,6 +78,7 @@ class FinalMeta(ABCMeta):
|
|||
cls._name_per_meta_cls[cls] = implementation
|
||||
|
||||
def __new__(cls, name: str, *args: Any, **kwargs: Any) -> type:
|
||||
"""Prevent subclasses, return from internal dict instead"""
|
||||
if name == cls._name_per_meta_cls[cls]:
|
||||
assert name, "cls_name not set"
|
||||
return type.__new__(cls, name, *args, **kwargs)
|
||||
|
@ -105,8 +108,7 @@ class PrintableMeta(ABCMeta):
|
|||
"""
|
||||
|
||||
@abstractmethod
|
||||
def __str__(cls) -> str:
|
||||
... # pragma: no cover
|
||||
def __str__(cls) -> str: ... # pragma: no cover
|
||||
|
||||
def __repr__(cls) -> str:
|
||||
return str(cls)
|
||||
|
@ -122,8 +124,7 @@ class SubscriptableMeta(ABCMeta):
|
|||
_parameterized: bool = False
|
||||
|
||||
@abstractmethod
|
||||
def _get_item(cls, item: Any) -> Tuple[Any, ...]:
|
||||
... # pragma: no cover
|
||||
def _get_item(cls, item: Any) -> Tuple[Any, ...]: ... # pragma: no cover
|
||||
|
||||
def _get_module(cls, stack: List[FrameInfo], module: str) -> str:
|
||||
# The magic below makes Python's help function display a meaningful
|
||||
|
@ -201,12 +202,10 @@ class ContainerMeta(
|
|||
__args__: Tuple[str, ...]
|
||||
|
||||
@abstractmethod
|
||||
def _validate_expression(cls, item: str) -> None:
|
||||
... # pragma: no cover
|
||||
def _validate_expression(cls, item: str) -> None: ... # pragma: no cover
|
||||
|
||||
@abstractmethod
|
||||
def _normalize_expression(cls, item: str) -> str:
|
||||
... # pragma: no cover
|
||||
def _normalize_expression(cls, item: str) -> str: ... # pragma: no cover
|
||||
|
||||
def _get_item(cls, item: Any) -> Tuple[Any, ...]:
|
||||
if not isinstance(item, str):
|
||||
|
|
2
src/numpydantic/vendor/nptyping/ndarray.py
vendored
2
src/numpydantic/vendor/nptyping/ndarray.py
vendored
|
@ -21,12 +21,12 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
import inspect
|
||||
from abc import ABC
|
||||
from typing import Any, Tuple
|
||||
|
||||
import numpy as np
|
||||
|
||||
from nptyping.base_meta_classes import (
|
||||
FinalMeta,
|
||||
ImmutableMeta,
|
||||
|
|
|
@ -21,10 +21,11 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
from abc import ABC
|
||||
|
||||
|
||||
class NPTypingType(ABC):
|
||||
class NPTypingType(ABC): # noqa: B024
|
||||
"""
|
||||
Baseclass for all nptyping types.
|
||||
"""
|
||||
|
|
|
@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
__title__ = "nptyping"
|
||||
__version__ = "2.5.0"
|
||||
__author__ = "Ramon Hagenaars"
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
"""
|
||||
Pandas dataframe types
|
||||
"""
|
|
@ -21,12 +21,12 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
import inspect
|
||||
from abc import ABC
|
||||
from typing import Any, Tuple
|
||||
|
||||
import numpy as np
|
||||
|
||||
from nptyping import InvalidArgumentsError
|
||||
from nptyping.base_meta_classes import (
|
||||
FinalMeta,
|
||||
|
@ -91,7 +91,7 @@ class DataFrameMeta(
|
|||
if item is Any:
|
||||
return (Any,)
|
||||
cls._check_item(item)
|
||||
return (Structure[getattr(item, "__args__")[0]],)
|
||||
return (Structure[item.__args__[0]],)
|
||||
|
||||
def __str__(cls) -> str:
|
||||
structure = cls.__args__[0]
|
||||
|
|
|
@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
from nptyping.typing_ import Object
|
||||
from nptyping.typing_ import dtype_per_name as dtype_per_name_default
|
||||
|
||||
|
|
2
src/numpydantic/vendor/nptyping/recarray.py
vendored
2
src/numpydantic/vendor/nptyping/recarray.py
vendored
|
@ -21,11 +21,11 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
import inspect
|
||||
from typing import Any, Tuple
|
||||
|
||||
import numpy as np
|
||||
|
||||
from nptyping.error import InvalidArgumentsError
|
||||
from nptyping.ndarray import NDArray, NDArrayMeta
|
||||
from nptyping.structure import Structure
|
||||
|
|
1
src/numpydantic/vendor/nptyping/shape.py
vendored
1
src/numpydantic/vendor/nptyping/shape.py
vendored
|
@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
from abc import ABC
|
||||
from typing import Any, Dict
|
||||
|
||||
|
|
1
src/numpydantic/vendor/nptyping/shape.pyi
vendored
1
src/numpydantic/vendor/nptyping/shape.pyi
vendored
|
@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
try:
|
||||
from typing import Literal # type: ignore[attr-defined]
|
||||
except ImportError:
|
||||
|
|
|
@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
import re
|
||||
import string
|
||||
from functools import lru_cache
|
||||
|
@ -39,7 +40,7 @@ if TYPE_CHECKING:
|
|||
from nptyping.shape import Shape # pragma: no cover
|
||||
|
||||
|
||||
@lru_cache()
|
||||
@lru_cache
|
||||
def check_shape(shape: ShapeTuple, target: "Shape") -> bool:
|
||||
"""
|
||||
Check whether the given shape corresponds to the given shape_expression.
|
||||
|
|
1
src/numpydantic/vendor/nptyping/structure.py
vendored
1
src/numpydantic/vendor/nptyping/structure.py
vendored
|
@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
from abc import ABC
|
||||
from typing import (
|
||||
Any,
|
||||
|
|
|
@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
try:
|
||||
from typing import Literal # type: ignore[attr-defined]
|
||||
except ImportError:
|
||||
|
|
|
@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
import re
|
||||
from collections import Counter, defaultdict
|
||||
from difflib import get_close_matches
|
||||
|
@ -37,7 +38,6 @@ from typing import (
|
|||
)
|
||||
|
||||
import numpy as np
|
||||
|
||||
from nptyping.error import InvalidShapeError, InvalidStructureError
|
||||
from nptyping.shape import Shape
|
||||
from nptyping.shape_expression import (
|
||||
|
@ -109,8 +109,7 @@ def check_structure(
|
|||
return False
|
||||
|
||||
def iterator() -> Generator[Tuple[str, Tuple[np.dtype, int]], None, None]: # type: ignore[type-arg] # pylint: disable=line-too-long
|
||||
for name_, dtype_tuple_ in fields.items():
|
||||
yield name_, dtype_tuple_ # type: ignore[misc]
|
||||
yield from fields.items()
|
||||
|
||||
for name, dtype_tuple in iterator():
|
||||
field_in_target_not_in_subject = dtype_tuple is None
|
||||
|
|
20
src/numpydantic/vendor/nptyping/typing_.py
vendored
20
src/numpydantic/vendor/nptyping/typing_.py
vendored
|
@ -22,22 +22,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||
SOFTWARE.
|
||||
"""
|
||||
|
||||
try:
|
||||
from typing import ( # type: ignore[attr-defined,misc] # pylint: disable=unused-import
|
||||
Literal,
|
||||
TypeAlias,
|
||||
TypeGuard,
|
||||
final,
|
||||
)
|
||||
except ImportError: # pragma: no cover
|
||||
from typing_extensions import ( # type: ignore[attr-defined,misc]
|
||||
Literal,
|
||||
TypeAlias,
|
||||
TypeGuard,
|
||||
final,
|
||||
)
|
||||
|
||||
from typing import Tuple, Union
|
||||
from typing import ( # type: ignore[attr-defined,misc] # pylint: disable=unused-import
|
||||
Tuple,
|
||||
TypeAlias,
|
||||
Union,
|
||||
)
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
|
Loading…
Reference in a new issue