-
Notifications
You must be signed in to change notification settings - Fork 19
[Feat] Add type hints #251
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
base: develop
Are you sure you want to change the base?
Conversation
|
Not quite done but already in decent shape for a review @s-kuberski @jkuhl-uni:
For now I ignored the |
|
Great, thanks a lot for all of your work! I'll have a look in the upcoming week. |
pyerrors/correlators.py
Outdated
| __slots__ = ["content", "N", "T", "tag", "prange"] | ||
|
|
||
| def __init__(self, data_input, padding=[0, 0], prange=None): | ||
| def __init__(self, data_input: Any, padding: list[int]=[0, 0], prange: Optional[list[int]]=None): |
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.
Shouldn't this be list[Obs]? Alternatively, in the list, there could be something Obs-like, I suppose, such as list[CObs]?
|
Hey @fjosw, |
|
Hi, |
| N_sigma_dict: dict[str, int] = {} | ||
|
|
||
| def __init__(self, samples, names, idl=None, **kwargs): | ||
| def __init__(self, samples: list[Union[ndarray, list[Any]]], names: list[str], idl: Optional[Union[list[list[int]], list[Union[list[int], range]], list[range]]]=None, **kwargs): |
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.
Could one make this more concrete? Is this Union[None, float, int]?
Or if this used as we also allow np types?
|
|
||
|
|
||
| def read_ExternalLeg_hd5(path, filestem, ens_id, idl=None): | ||
| def read_ExternalLeg_hd5(path: str, filestem: str, ens_id: str, idl: Optional[range]=None): |
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.
| def read_ExternalLeg_hd5(path: str, filestem: str, ens_id: str, idl: Optional[range]=None): | |
| def read_ExternalLeg_hd5(path: str, filestem: str, ens_id: str, idl: Optional[Union[list, range]]=None): |
|
|
||
|
|
||
| def extract_t0_hd5(path, filestem, ens_id, obs='Clover energy density', fit_range=5, idl=None, **kwargs): | ||
| def extract_t0_hd5(path: str, filestem: str, ens_id: str, obs='Clover energy density', fit_range: int=5, idl: Optional[range]=None, **kwargs): |
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.
| def extract_t0_hd5(path: str, filestem: str, ens_id: str, obs='Clover energy density', fit_range: int=5, idl: Optional[range]=None, **kwargs): | |
| def extract_t0_hd5(path: str, filestem: str, ens_id: str, obs='Clover energy density', fit_range: int=5, idl: Optional[Union[list, range]]=None, **kwargs): |
|
|
||
|
|
||
| def read_meson_hd5(path, filestem, ens_id, meson='meson_0', idl=None, gammas=None): | ||
| def read_meson_hd5(path: str, filestem: str, ens_id: str, meson: str='meson_0', idl: Optional[range]=None, gammas: Optional[tuple[str, ...]]=None): |
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.
| def read_meson_hd5(path: str, filestem: str, ens_id: str, meson: str='meson_0', idl: Optional[range]=None, gammas: Optional[tuple[str, ...]]=None): | |
| def read_meson_hd5(path: str, filestem: str, ens_id: str, meson: str='meson_0', idl: Optional[Union[list, range]]=None, gammas: Optional[tuple[str, ...]]=None): |
|
|
||
|
|
||
| def read_hd5(filestem, ens_id, group, attrs=None, idl=None, part="real"): | ||
| def read_hd5(filestem: str, ens_id: str, group: str, attrs: Optional[Union[dict, int]]=None, idl=None, part="real") -> Corr: |
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.
| def read_hd5(filestem: str, ens_id: str, group: str, attrs: Optional[Union[dict, int]]=None, idl=None, part="real") -> Corr: | |
| def read_hd5(filestem: str, ens_id: str, group: str, attrs: Optional[Union[dict, int]]=None, idl:Optional[Union[list, range]]=None, part="real") -> Corr: |
|
|
||
|
|
||
| def read_Fourquark_hd5(path, filestem, ens_id, idl=None, vertices=["VA", "AV"]): | ||
| def read_Fourquark_hd5(path: str, filestem: str, ens_id: str, idl: Optional[range]=None, vertices: list[str]=["VA", "AV"]): |
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.
| def read_Fourquark_hd5(path: str, filestem: str, ens_id: str, idl: Optional[range]=None, vertices: list[str]=["VA", "AV"]): | |
| def read_Fourquark_hd5(path: str, filestem: str, ens_id: str, idl: Optional[Union[list, range]]=None, vertices: list[str]=["VA", "AV"]): |
| path = kwargs.get('path') | ||
| if path is not None: | ||
| if not isinstance(path, str): | ||
| raise Exception("Path has to be a string.") | ||
| file_name = path + '/' + name + '.p' | ||
| else: | ||
| file_name = name + '.p' |
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.
| path = kwargs.get('path') | |
| if path is not None: | |
| if not isinstance(path, str): | |
| raise Exception("Path has to be a string.") | |
| file_name = path + '/' + name + '.p' | |
| else: | |
| file_name = name + '.p' | |
| path = kwargs.get('path', '.') | |
| if not isinstance(path, str): | |
| raise Exception("Path has to be a string.") | |
| file_name = path + '/' + name + '.p' |
| intern[name]["spec"][quarks][off][w][w2]["pattern"] = _make_pattern(version, name, off, w, w2, intern[name]['b2b'], quarks) | ||
| else: | ||
| intern[name]["spec"][quarks][off][w]["0"] = {} | ||
| intern[name]["spec"][quarks][off][w]["0"]["pattern"] = _make_pattern(version, name, off, w, 0, intern[name]['b2b'], quarks) |
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.
| intern[name]["spec"][quarks][off][w]["0"]["pattern"] = _make_pattern(version, name, off, w, 0, intern[name]['b2b'], quarks) | |
| intern[name]["spec"][quarks][off][w]["0"]["pattern"] = _make_pattern(version, name, off, w, "0", intern[name]['b2b'], quarks) |
|
|
||
|
|
||
| def _make_pattern(version, name, noffset, wf, wf2, b2b, quarks): | ||
| def _make_pattern(version: str, name: str, noffset: str, wf: str, wf2: Union[str, int], b2b: bool, quarks: str) -> str: |
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.
| def _make_pattern(version: str, name: str, noffset: str, wf: str, wf2: Union[str, int], b2b: bool, quarks: str) -> str: | |
| def _make_pattern(version: str, name: str, noffset: str, wf: str, wf2: str, b2b: bool, quarks: str) -> str: |
| path = kwargs.get('path') | ||
| if path is not None: | ||
| if not isinstance(path, str): | ||
| raise TypeError('path has to be a string.') | ||
| file_name = path + '/' + filename | ||
| else: | ||
| file_name = filename |
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.
| path = kwargs.get('path') | |
| if path is not None: | |
| if not isinstance(path, str): | |
| raise TypeError('path has to be a string.') | |
| file_name = path + '/' + filename | |
| else: | |
| file_name = filename | |
| path = kwargs.get('path', '.') | |
| if not isinstance(path, str): | |
| raise TypeError('path has to be a string.') | |
| file_name = path + '/' + filename |
As a first step towards adding type hints, I added automatic type hints with monkeytype. Hints for the more complicated methods will need additional manual work but for the simpler methods this seems to have worked quite well.