-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix & normalize typing for chunks #8247
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,9 @@ | |
|
||
try: | ||
if sys.version_info >= (3, 11): | ||
from typing import Self | ||
from typing import Self, TypeAlias | ||
else: | ||
from typing_extensions import Self | ||
from typing_extensions import Self, TypeAlias | ||
except ImportError: | ||
if TYPE_CHECKING: | ||
raise | ||
|
@@ -183,7 +183,12 @@ def copy( | |
Dims = Union[str, Iterable[Hashable], "ellipsis", None] | ||
OrderedDims = Union[str, Sequence[Union[Hashable, "ellipsis"]], "ellipsis", None] | ||
|
||
T_Chunks = Union[int, dict[Any, Any], Literal["auto"], None] | ||
# FYI in some cases we don't allow `None`, which this doesn't take account of. | ||
T_ChunkDim: TypeAlias = Union[int, Literal["auto"], None, tuple[int, ...]] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Slowly we should agree on a naming convention, haha. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha! I even went back & forth on whether this should be |
||
# We allow the tuple form of this (though arguably we could transition to named dims only) | ||
T_Chunks: TypeAlias = Union[ | ||
T_ChunkDim, Mapping[Any, T_ChunkDim], tuple[T_ChunkDim, ...] | ||
] | ||
T_NormalizedChunks = tuple[tuple[int, ...], ...] | ||
|
||
DataVars = Mapping[Any, Any] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait... is the above check for None correct? I'm not sure that the chunks_kwargs can be None, isn't it always a dict? So this would make the warning not reachable...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think
chunks_kwargs
can beNone
, butchunks
can... Does that answer your Q?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it answers the question.
But then this means that the above code is wrong because the if statement is never reachable...
Doesn't need to be fixed in this PR, but maybe rewriting this will remove the need for the type ignore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see what you mean...