Created
December 25, 2022 11:23
-
-
Save jenshnielsen/4228299cea8fea4bfaa9a8bd9185f229 to your computer and use it in GitHub Desktop.
some experimentation with pyright
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
# https://github.com/microsoft/pyright/issues/219 | |
def test_conditional( | |
z: str | bool, | |
) -> None: | |
z_is_stringy = isinstance(z, str) | |
if z_is_stringy: | |
z_upper = z.upper() | |
if z_is_stringy: | |
N = len(z_upper) |
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
from __future__ import annotations | |
from typing import cast, Any | |
def apply_color_scale_limits( | |
data_array: list[int] | None = None, | |
) -> None: | |
if data_array is None: | |
default_value = get_list_as_any() | |
cast_value = cast(list[int], default_value) | |
data_array = default_value | |
reveal_type(default_value) | |
reveal_type(cast_value) | |
reveal_type(data_array) | |
reveal_type(data_array) | |
def get_list_as_any() -> Any: | |
return [1,2,3] |
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
import numpy as np | |
import numpy.typing as npt | |
def _on_rectilinear_grid_except_nan(x_data: npt.NDArray[np.floating], y_data: npt.NDArray[np.floating]) -> bool: | |
""" | |
check that data is on a rectilinear grid. e.g. all points are the same as the first | |
row and column with the exception of nans. Those represent points not yet measured. | |
""" | |
x_row = x_data[:, 0:1] | |
y_row = y_data[0:1, :] | |
return ( | |
np.nanmax(np.abs(x_data - x_row)) == 0 | |
and np.nanmax(np.abs(y_data - y_row)) == 0 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment