Skip to content

Commit 79838da

Browse files
committed
TYP: support PEP 800 type checks (disjoint bases)
1 parent b693757 commit 79838da

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ tests = [
4545
"Cython",
4646
"packaging",
4747
"pytest",
48+
"typing-extensions>=4.15.0",
4849
]
4950
parallel = [
5051
"mpi4py",

‎src/netCDF4/__init__.pyi‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ from typing import (
3434
TYPE_CHECKING,
3535
Any,
3636
Callable,
37+
final,
3738
Final,
3839
Generic,
3940
Iterable,
@@ -51,7 +52,7 @@ from typing import (
5152
import cftime
5253
import numpy as np
5354
import numpy.typing as npt
54-
from typing_extensions import Buffer, Self, TypeAlias
55+
from typing_extensions import Buffer, Self, TypeAlias, disjoint_base
5556

5657
__all__ = [
5758
"Dataset",
@@ -217,6 +218,7 @@ class NetCDF4MissingFeatureException(Exception):
217218

218219
def dtype_is_complex(dtype: str) -> bool: ...
219220

221+
@disjoint_base
220222
class Dataset:
221223
def __init__(
222224
self,
@@ -398,6 +400,7 @@ class Group(Dataset):
398400
def __init__(self, parent: Dataset, name: str, **kwargs: Any) -> None: ...
399401
def close(self) -> NoReturn: ...
400402

403+
@final
401404
class Dimension:
402405
def __init__(self, grp: Dataset, name: str, size: int | None = None, **kwargs: Any) -> None: ...
403406
@property
@@ -430,6 +433,7 @@ class _VarDtypeProperty:
430433
@overload
431434
def __get__(self, instance: Variable, owner: Any) -> Any: ... # actual return type np.dtype | Type[str]
432435

436+
@final
433437
class Variable(Generic[VarT]):
434438
# Overloads of __new__ are provided for some cases where the Variable's type may be statically inferred from the datatype arg
435439
@overload
@@ -590,6 +594,7 @@ class Variable(Generic[VarT]):
590594
def __len__(self) -> int: ...
591595
def __iter__(self) -> Iterator[Any]: ... # faux method so mypy believes Variable is iterable
592596

597+
@final
593598
class CompoundType:
594599
dtype: np.dtype
595600
dtype_view: np.dtype
@@ -600,13 +605,15 @@ class CompoundType:
600605
) -> None: ...
601606
def __reduce__(self) -> NoReturn: ...
602607

608+
@final
603609
class VLType:
604610
dtype: np.dtype
605611
name: str | None
606612

607613
def __init__(self, grp: Dataset, dt: npt.DTypeLike, dtype_name: str, **kwargs: Any) -> None: ...
608614
def __reduce__(self) -> NoReturn: ...
609615

616+
@final
610617
class EnumType:
611618
dtype: np.dtype[np.integer]
612619
name: str

0 commit comments

Comments
 (0)