diff --git a/.github/stubtest-allowlist b/.github/stubtest-allowlist index 2d848ab15..a3bd3a1a4 100644 --- a/.github/stubtest-allowlist +++ b/.github/stubtest-allowlist @@ -14,6 +14,7 @@ netCDF4.FiltersDict netCDF4.SzipInfo netCDF4.BloscInfo netCDF4.BoolInt +netCDF4.GetSetItemKey netCDF4.T_Datatype netCDF4.T_DatatypeNC netCDF4.Dataset.__dealloc diff --git a/src/netCDF4/__init__.pyi b/src/netCDF4/__init__.pyi index 11bd10bbe..413336f0e 100644 --- a/src/netCDF4/__init__.pyi +++ b/src/netCDF4/__init__.pyi @@ -555,6 +555,14 @@ class _Variable: def __init__(self, dset: Dataset, varname: str, var: Variable[Any], recdimname: str) -> None: ... + # shape, ndim, and name actually come from __getattr__ + @property + def shape(self) -> tuple[int, ...]: ... + @property + def ndim(self) -> int: ... + @property + def name(self) -> str: ... + def typecode(self) -> np.dtype | type[str]: ... def ncattrs(self) -> list[str]: ... def _shape(self) -> tuple[int, ...]: ... @@ -582,9 +590,38 @@ class MFTime(_Variable): def __getitem__(self, elem: GetSetItemKey) -> np.ndarray: ... -def stringtoarr(string, NUMCHARS: int, dtype: Literal['S', 'U'] = 'S') -> np.ndarray: ... -def stringtochar(a, encoding: str | bytes | None = 'utf-8') -> np.ndarray: ... -def chartostring(b, encoding: str | bytes | None = 'utf-8') -> np.ndarray: ... +@overload +def stringtoarr( + string: str, + NUMCHARS: int, + dtype: Literal["S"] | np.dtype[np.bytes_]= "S", +) -> npt.NDArray[np.bytes_]: ... +@overload +def stringtoarr( + string: str, + NUMCHARS: int, + dtype: Literal["U"] | np.dtype[np.str_], +) -> npt.NDArray[np.str_]: ... +@overload +def stringtochar( + a: npt.NDArray[np.character], + encoding: Literal["none", "None", "bytes"], +) -> npt.NDArray[np.bytes_]: ... +@overload +def stringtochar( + a: npt.NDArray[np.character], + encoding: str = ..., +) -> npt.NDArray[np.str_] | npt.NDArray[np.bytes_]: ... +@overload +def chartostring( + b: npt.NDArray[np.character], + encoding: Literal["none", "None", "bytes"] = ..., +) -> npt.NDArray[np.bytes_]: ... +@overload +def chartostring( + b: npt.NDArray[np.character], + encoding: str = ..., +) -> npt.NDArray[np.str_] | npt.NDArray[np.bytes_]: ... def getlibversion() -> str: ...