Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax Axes type ctor to accept variable length tuple #46

Merged
merged 1 commit into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion repESP/cube_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def parse_axis(line: str) -> GridMesh.Axis:

return GridMesh(
origin,
GridMesh.Axes(tuple( # type: ignore # (asserted len is 3)
GridMesh.Axes(tuple(
parse_axis(line) for line in lines
))
)
Expand Down
10 changes: 8 additions & 2 deletions repESP/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from abc import ABC, abstractmethod
from dataclasses import dataclass, field, InitVar
from typing import Any, cast, Collection, Generic, Iterator, List, NewType, Tuple, Type, TypeVar
from typing import Any, cast, Collection, Generic, Iterable, Iterator, List, NewType, Tuple, Type, TypeVar

import functools
import math
Expand Down Expand Up @@ -178,7 +178,13 @@ def __post_init__(self) -> None:
f"Negative value of `point_count` given: {self.point_count}."
)

Axes = NewType("Axes", Tuple[Axis, Axis, Axis])
_AxesT = TypeVar('_AxesT', bound='Axes')
class Axes(Tuple[Axis, Axis, Axis]):
def __new__(cls: Type["GridMesh._AxesT"], values: Iterable["GridMesh.Axis"]) -> "GridMesh._AxesT":
self_to_be = super().__new__(cls, values)
if len(self_to_be) != 3:
raise ValueError("Axes constructor expected an iterable yielding three elements.")
return self_to_be

origin: Coords
axes: Axes
Expand Down