Skip to content

Commit db03592

Browse files
committed
add some properties and overloads
1 parent d0e9bd4 commit db03592

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

‎.github/stubtest-allowlist‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ netCDF4.FiltersDict
1414
netCDF4.SzipInfo
1515
netCDF4.BloscInfo
1616
netCDF4.BoolInt
17+
netCDF4.GetSetItemKey
1718
netCDF4.T_Datatype
1819
netCDF4.T_DatatypeNC
1920
netCDF4.Dataset.__dealloc

‎src/netCDF4/__init__.pyi‎

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,14 @@ class _Variable:
555555

556556
def __init__(self, dset: Dataset, varname: str, var: Variable[Any], recdimname: str) -> None: ...
557557

558+
# shape, ndim, and name actually come from __getattr__
559+
@property
560+
def shape(self) -> tuple[int, ...]: ...
561+
@property
562+
def ndim(self) -> int: ...
563+
@property
564+
def name(self) -> str: ...
565+
558566
def typecode(self) -> np.dtype | type[str]: ...
559567
def ncattrs(self) -> list[str]: ...
560568
def _shape(self) -> tuple[int, ...]: ...
@@ -582,9 +590,38 @@ class MFTime(_Variable):
582590
def __getitem__(self, elem: GetSetItemKey) -> np.ndarray: ...
583591

584592

585-
def stringtoarr(string, NUMCHARS: int, dtype: Literal['S', 'U'] = 'S') -> np.ndarray: ...
586-
def stringtochar(a, encoding: str | bytes | None = 'utf-8') -> np.ndarray: ...
587-
def chartostring(b, encoding: str | bytes | None = 'utf-8') -> np.ndarray: ...
593+
@overload
594+
def stringtoarr(
595+
string: str,
596+
NUMCHARS: int,
597+
dtype: Literal["S"] | np.dtype[np.bytes_]= "S",
598+
) -> npt.NDArray[np.bytes_]: ...
599+
@overload
600+
def stringtoarr(
601+
string: str,
602+
NUMCHARS: int,
603+
dtype: Literal["U"] | np.dtype[np.str_],
604+
) -> npt.NDArray[np.str_]: ...
605+
@overload
606+
def stringtochar(
607+
a: npt.NDArray[np.character],
608+
encoding: Literal["none", "None", "bytes"],
609+
) -> npt.NDArray[np.bytes_]: ...
610+
@overload
611+
def stringtochar(
612+
a: npt.NDArray[np.character],
613+
encoding: str = ...,
614+
) -> npt.NDArray[np.str_] | npt.NDArray[np.bytes_]: ...
615+
@overload
616+
def chartostring(
617+
b: npt.NDArray[np.character],
618+
encoding: Literal["none", "None", "bytes"] = ...,
619+
) -> npt.NDArray[np.bytes_]: ...
620+
@overload
621+
def chartostring(
622+
b: npt.NDArray[np.character],
623+
encoding: str = ...,
624+
) -> npt.NDArray[np.str_] | npt.NDArray[np.bytes_]: ...
588625

589626
def getlibversion() -> str: ...
590627

0 commit comments

Comments
 (0)