-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from scipp/some-typing-improvements
Some typing improvements
- Loading branch information
Showing
9 changed files
with
77 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,71 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright (c) 2022 Scipp contributors (https://github.com/scipp) | ||
# @author Simon Heybrock | ||
from typing import Protocol, Union, Tuple, Dict, List, Callable | ||
from __future__ import annotations | ||
from typing import Any, Protocol, Union, Tuple, Dict, List, Callable | ||
from typing import TYPE_CHECKING | ||
|
||
|
||
class H5Base(Protocol): | ||
@property | ||
def attrs(self) -> List[int]: | ||
"""Attributes of dataset or group""" | ||
|
||
@property | ||
def name(self) -> str: | ||
"""Name of dataset or group""" | ||
|
||
@property | ||
def file(self) -> List[int]: | ||
"""File of dataset or group""" | ||
|
||
@property | ||
def parent(self) -> H5Group: | ||
"""Parent of dataset or group""" | ||
|
||
|
||
# TODO Define more required methods | ||
class H5Dataset(Protocol): | ||
class H5Dataset(H5Base, Protocol): | ||
"""h5py.Dataset-like""" | ||
@property | ||
def shape(self) -> List[int]: | ||
"""Shape of a dataset""" | ||
|
||
@property | ||
def dtype(self) -> List[int]: | ||
"""dtype of a dataset""" | ||
|
||
def read_direct(self, array) -> None: | ||
"""Read dataset into given buffer""" | ||
|
||
|
||
class H5Group(Protocol): | ||
class H5Group(H5Base, Protocol): | ||
"""h5py.Group-like""" | ||
def __getitem__(self, index: Union[str, Any]) -> Union[H5Dataset, H5Group]: | ||
"""Keys in the group""" | ||
|
||
def keys(self) -> List[str]: | ||
"""Keys in the group""" | ||
|
||
def create_dataset(self) -> H5Dataset: | ||
"""Create a dataset""" | ||
|
||
def create_group(self) -> H5Group: | ||
"""Create a group""" | ||
|
||
def visititems(self, func: Callable) -> None: | ||
"""""" | ||
"""Apply callable to all items, recursively""" | ||
|
||
|
||
if TYPE_CHECKING: | ||
from enum import Enum | ||
|
||
class ellipsis(Enum): | ||
Ellipsis = "..." | ||
else: | ||
ellipsis = type(Ellipsis) | ||
|
||
# Note that scipp does not support dicts yet, but this HDF5 code does, to | ||
# allow for loading blocks of 2d (or higher) data efficiently. | ||
ScippIndex = Union[type(Ellipsis), int, slice, Tuple[str, Union[int, slice]], | ||
ScippIndex = Union[ellipsis, int, tuple, slice, Tuple[str, Union[int, slice]], | ||
Dict[str, Union[int, slice]]] |