Skip to content

Commit

Permalink
Merge pull request #193 from jorenham/maintenance/basedpyright-1.22.0
Browse files Browse the repository at this point in the history
bump `basedpyright` to `1.22.0`
  • Loading branch information
jorenham authored Nov 23, 2024
2 parents ac1c1ec + af2c458 commit 4dd68a3
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 109 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ repos:
args: [--markdown-linebreak-ext=md]

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.42.0
rev: v0.43.0
hooks:
- id: markdownlint

Expand Down
4 changes: 3 additions & 1 deletion codegen/mods.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ]
# ///

from typing import Final
from typing import Final, final
from typing_extensions import override

import libcst as cst
Expand Down Expand Up @@ -53,6 +53,7 @@ def leave_Module(self, original_node: cst.Module, updated_node: cst.Module) -> c
return updated_node


@final
class AnnotateMissing(_BaseMod):
DESCRIPTION = "Sets the default return type to `None`, and other missing annotations to `scipy._typing.Untyped`"

Expand Down Expand Up @@ -94,6 +95,7 @@ def leave_FunctionDef(self, /, original_node: cst.FunctionDef, updated_node: cst
return updated_node


@final
class FixTrailingComma(_BaseMod):
DESCRIPTION = "Adds a trailing comma to parameters that don't fit on one line, so that ruff formats them correctly."

Expand Down
143 changes: 80 additions & 63 deletions poetry.lock

Large diffs are not rendered by default.

38 changes: 28 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ tox = "^4.23.2"

[tool.poetry.group.lint.dependencies]
basedmypy = {version = "^2.7.0", extras = ["faster-cache"]}
basedpyright = "^1.21.1"
basedpyright = "^1.22.0"
codespell = "^2.3.0"
mdformat = "^0.7.19"
mdformat-gfm = "^0.3.7"
Expand Down Expand Up @@ -151,18 +151,36 @@ stubPath = "."
pythonVersion = "3.10"
pythonPlatform = "All"
typeCheckingMode = "strict"

deprecateTypingAliases = true
# ignore comments
enableTypeIgnoreComments = false
reportIgnoreCommentWithoutRule = true
reportImplicitRelativeImport = true
reportInvalidCast = true
reportIgnoreCommentWithoutRule = true # based
reportUnnecessaryTypeIgnoreComment = true

# imports
reportImplicitRelativeImport = true # based
reportPrivateLocalImportUsage = false # based
reportShadowedImports = true
# classes and inheritance
reportUnsafeMultipleInheritance = true # based
reportImplicitAbstractClass = true # based
reportImplicitOverride = true
reportUnannotatedClassAttribute = true # based
# linting
deprecateTypingAliases = true
enableReachabilityAnalysis = false # discouraged
reportCallInDefaultInitializer = true
reportImplicitStringConcatenation = true # based
reportPrivateUsage = false
# narrowing
strictGenericNarrowing = true # based
# TODO: enable once nothing is `Untyped`
reportAny = false # based
reportExplicitAny = false # based
# environment
failOnWarnings = true # based
executionEnvironments = [
{root = "codegen", reportUnusedParameter = false},
{root = "scipy-stubs", reportDeprecated = false, reportPrivateUsage = false},
{root = "tests", reportPrivateUsage = false, reportInvalidStubStatement = false},
{root = "scipy-stubs", reportDeprecated = false, reportUnsafeMultipleInheritance = false, reportUnreachable = false},
{root = "codegen", reportAny = true, reportExplicitAny = true, reportInvalidCast = true, reportPrivateUsage = true},
{root = "tests", reportAny = true, reportInvalidCast = true, reportInvalidStubStatement = false},
]

[tool.repo-review]
Expand Down
3 changes: 2 additions & 1 deletion scipy-stubs/_lib/_ccallback.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class _CFFIVoid(_CFFIType, Protocol):

@type_check_only
class _CFFIFunc(_CFFIType, Protocol[_CT_co, Unpack[_CTs]]):
is_array_type: ClassVar = False
is_array_type: ClassVar[bool] = False

@property
def args(self, /) -> tuple[Unpack[_CTs]]: ...
Expand All @@ -78,6 +78,7 @@ class _CFFIFuncPtr(_CFFIFunc[_CT_co, Unpack[_CTs]], Protocol[_CT_co, Unpack[_CTs
def as_raw_function(self, /) -> _CFFIFunc[_CT_co, Unpack[_CTs]]: ...

@type_check_only
@final
class _CFFIPointerType(_CFFIType, Protocol[_CT_co]):
is_array_type: ClassVar = False
is_raw_function: ClassVar = False
Expand Down
4 changes: 2 additions & 2 deletions scipy-stubs/fft/_backend.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from collections.abc import Mapping, Sequence
from typing import Any, ClassVar, Protocol, final, type_check_only
from typing_extensions import TypeVar
from typing_extensions import LiteralString, TypeVar

import optype as op

_RT_co = TypeVar("_RT_co", covariant=True, default=Any)

@type_check_only
class _BaseBackend(Protocol[_RT_co]):
__ua_domain__: ClassVar = "numpy.scipy.fft"
__ua_domain__: ClassVar[LiteralString] = "numpy.scipy.fft"
@staticmethod
def __ua_function__(method: str, args: Sequence[object], kwargs: Mapping[str, object]) -> _RT_co: ...

Expand Down
4 changes: 2 additions & 2 deletions scipy-stubs/integrate/_ode.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class zvode(vode[np.complex128]):
initialized: bool

class dopri5(IntegratorBase[np.float64]):
name: ClassVar = "dopri5"
name: ClassVar[str] = "dopri5"
messages: ClassVar[dict[int, str]] = ...

rtol: Final[float]
Expand Down Expand Up @@ -233,7 +233,7 @@ class dopri5(IntegratorBase[np.float64]):
) -> Literal[0, -1, 1]: ...

class dop853(dopri5):
name: ClassVar = "dop853"
name: ClassVar[str] = "dop853"
def __init__(
self,
/,
Expand Down
28 changes: 14 additions & 14 deletions scipy-stubs/io/_mmio.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ def mmwrite(
) -> None: ...

class MMFile:
FORMAT_COORDINATE: ClassVar = "coordinate"
FORMAT_ARRAY: ClassVar = "array"
FORMAT_VALUES: ClassVar = "coordinate", "array"
FORMAT_COORDINATE: ClassVar[str] = "coordinate"
FORMAT_ARRAY: ClassVar[str] = "array"
FORMAT_VALUES: ClassVar[tuple[str, ...]] = "coordinate", "array"

FIELD_INTEGER: ClassVar = "integer"
FIELD_UNSIGNED: ClassVar = "unsigned-integer"
FIELD_REAL: ClassVar = "real"
FIELD_COMPLEX: ClassVar = "complex"
FIELD_PATTERN: ClassVar = "pattern"
FIELD_VALUES: ClassVar = "integer", "unsigned-integer", "real", "complex", "pattern"
FIELD_INTEGER: ClassVar[str] = "integer"
FIELD_UNSIGNED: ClassVar[str] = "unsigned-integer"
FIELD_REAL: ClassVar[str] = "real"
FIELD_COMPLEX: ClassVar[str] = "complex"
FIELD_PATTERN: ClassVar[str] = "pattern"
FIELD_VALUES: ClassVar[tuple[str, ...]] = "integer", "unsigned-integer", "real", "complex", "pattern"

SYMMETRY_GENERAL: ClassVar = "general"
SYMMETRY_SYMMETRIC: ClassVar = "symmetric"
SYMMETRY_SKEW_SYMMETRIC: ClassVar = "skew-symmetric"
SYMMETRY_HERMITIAN: ClassVar = "hermitian"
SYMMETRY_VALUES: ClassVar = "general", "symmetric", "skew-symmetric", "hermitian"
SYMMETRY_GENERAL: ClassVar[str] = "general"
SYMMETRY_SYMMETRIC: ClassVar[str] = "symmetric"
SYMMETRY_SKEW_SYMMETRIC: ClassVar[str] = "skew-symmetric"
SYMMETRY_HERMITIAN: ClassVar[str] = "hermitian"
SYMMETRY_VALUES: ClassVar[tuple[str, ...]] = "general", "symmetric", "skew-symmetric", "hermitian"

DTYPES_BY_FIELD: ClassVar[dict[_Field, Literal["intp", "uint64", "d", "D"]]] = ...

Expand Down
12 changes: 6 additions & 6 deletions scipy-stubs/io/arff/_arffread.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ArffError(OSError): ...
class ParseArffError(ArffError): ...

class Attribute(Generic[_T_co], metaclass=abc.ABCMeta):
type_name: ClassVar[Any]
type_name: ClassVar[str | None]
dtype: Any
range: Any

Expand All @@ -41,7 +41,7 @@ class Attribute(Generic[_T_co], metaclass=abc.ABCMeta):
def parse_data(self, /, data_str: str) -> _T_co: ...

class NominalAttribute(Attribute[str]):
type_name: ClassVar = "nominal"
type_name: ClassVar[str | None] = "nominal"
dtype: tuple[type[np.bytes_], ...]
range: Sequence[str]

Expand All @@ -50,17 +50,17 @@ class NominalAttribute(Attribute[str]):
def __init__(self, /, name: str, values: Sequence[str]) -> None: ...

class NumericAttribute(Attribute[float]):
type_name: ClassVar = "numeric"
type_name: ClassVar[str | None] = "numeric"
dtype: type[np.float64]
range: None

class StringAttribute(Attribute[None]):
type_name: ClassVar = "string"
type_name: ClassVar[str | None] = "string"
dtype: type[np.object_]
range: None

class DateAttribute(Attribute[np.datetime64]):
type_name: ClassVar = "date"
type_name: ClassVar[str | None] = "date"
dtype: np.datetime64
range: str

Expand All @@ -70,7 +70,7 @@ class DateAttribute(Attribute[np.datetime64]):
def __init__(self, /, name: str, date_format: str, datetime_unit: str) -> None: ...

class RelationalAttribute(Attribute[np.ndarray[tuple[int], np.dtype[np.void]]]):
type_name: ClassVar = "relational"
type_name: ClassVar[str | None] = "relational"
dtype: type[np.object_]
range: None

Expand Down
54 changes: 54 additions & 0 deletions scipy-stubs/stats/_biasedurn.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# see `scipy/stats/_biasedurn.pyx`

from typing import type_check_only
from typing_extensions import Never

import numpy as np
import optype as op
import optype.numpy as onp
from scipy._typing import RNG

@type_check_only
class _PyNCHypergeometric:
def __init__(self, /, n: op.CanInt, m: op.CanInt, N: op.CanInt, odds: op.CanFloat, accuracy: op.CanFloat) -> None: ...
def mode(self, /) -> int: ...
def mean(self, /) -> float: ...
def variance(self, /) -> float: ...
def probability(self, /, x: op.CanInt) -> float: ...
def moments(self, /) -> tuple[float, float]: ...

###

class _PyFishersNCHypergeometric(_PyNCHypergeometric): ...
class _PyWalleniusNCHypergeometric(_PyNCHypergeometric): ...

class _PyStochasticLib3:
def __init__(self, /, *args: Never, **kwargs: Never) -> None: ...
def Random(self, /) -> float: ...
def SetAccuracy(self, /, accur: op.CanFloat) -> None: ...
def FishersNCHyp(self, /, n: op.CanInt, m: op.CanInt, N: op.CanInt, odds: op.CanFloat) -> _PyFishersNCHypergeometric: ...
def WalleniusNCHyp(self, /, n: op.CanInt, m: op.CanInt, N: op.CanInt, odds: op.CanFloat) -> _PyWalleniusNCHypergeometric: ...
#
def rvs_fisher(
self,
/,
n: op.CanInt,
m: op.CanInt,
N: op.CanInt,
odds: op.CanFloat,
size: op.CanInt,
random_state: RNG | None = None,
) -> onp.Array1D[np.float64]: ...
def rvs_wallenius(
self,
/,
n: op.CanInt,
m: op.CanInt,
N: op.CanInt,
odds: op.CanFloat,
size: op.CanInt,
random_state: RNG | None = None,
) -> onp.Array1D[np.float64]: ...

def __setstate_cython__(self: object, pyx_state: object, /) -> None: ...
def __reduce_cython__(self: object) -> None: ...
17 changes: 10 additions & 7 deletions scipy-stubs/stats/_discrete_distns.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import ClassVar, Final
from typing import ClassVar, Final, Literal, final

from ._biasedurn import _PyFishersNCHypergeometric, _PyWalleniusNCHypergeometric
from ._distn_infrastructure import rv_discrete

__all__ = [
Expand Down Expand Up @@ -65,16 +66,18 @@ class skellam_gen(rv_discrete): ...
class yulesimon_gen(rv_discrete): ...

class _nchypergeom_gen(rv_discrete):
rvs_name: ClassVar = None
dist: ClassVar = None
rvs_name: ClassVar[Literal["rvs_fisher", "rvs_wallenius"] | None] = None
dist: ClassVar[type[_PyFishersNCHypergeometric | _PyWalleniusNCHypergeometric] | None] = None

@final
class nchypergeom_fisher_gen(_nchypergeom_gen):
rvs_name: ClassVar = "rvs_fisher"
dist: ClassVar[type] = ... # scipy.stats._biasedurn._PyFishersNCHypergeometric
rvs_name: ClassVar[Literal["rvs_fisher"]] = "rvs_fisher" # pyright: ignore[reportIncompatibleVariableOverride]
dist: ClassVar[type[_PyFishersNCHypergeometric]] = ... # pyright: ignore[reportIncompatibleVariableOverride]

@final
class nchypergeom_wallenius_gen(_nchypergeom_gen):
rvs_name: ClassVar = "rvs_wallenius"
dist: ClassVar[type] = ... # scipy.stats._biasedurn._PyWalleniusNCHypergeometric
rvs_name: ClassVar[Literal["rvs_wallenius"]] = "rvs_wallenius" # pyright: ignore[reportIncompatibleVariableOverride]
dist: ClassVar[type[_PyWalleniusNCHypergeometric]] = ... # pyright: ignore[reportIncompatibleVariableOverride]

binom: Final[binom_gen]
bernoulli: Final[bernoulli_gen]
Expand Down
2 changes: 1 addition & 1 deletion scipy-stubs/stats/_kde.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class gaussian_kde:
weights: onp.ToFloat1D | onp.ToFloat2D | None = None,
) -> None: ...
def __call__(self, /, points: onp.ToFloat1D | onp.ToFloat2D) -> _Float1D: ...
evaluate = __call__
def evaluate(self, /, points: onp.ToFloat1D | onp.ToFloat2D) -> _Float1D: ...
def pdf(self, /, x: onp.ToFloat1D | onp.ToFloat2D) -> _Float1D: ...
def logpdf(self, /, x: onp.ToFloat1D | onp.ToFloat2D) -> _Float1D: ...
def integrate_gaussian(self, /, mean: onp.ToFloat1D, cov: onp.ToFloat2D) -> np.float64 | np.float32: ...
Expand Down
4 changes: 3 additions & 1 deletion scipy-stubs/stats/_stats_py.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass
from collections.abc import Callable, Sequence
from types import ModuleType
from typing import Any, Generic, Literal, Protocol, TypeAlias, overload, type_check_only
from typing import Any, Generic, Literal, Protocol, TypeAlias, final, overload, type_check_only
from typing_extensions import NamedTuple, Self, TypeVar

import numpy as np
Expand Down Expand Up @@ -109,6 +109,7 @@ _NDT_real_co = TypeVar("_NDT_real_co", covariant=True, bound=float | _RealND, de
class _RVSCallable(Protocol):
def __call__(self, /, *, size: int | tuple[int, ...]) -> onp.ArrayND[np.floating[Any]]: ...

@final
class _SimpleNormal:
@overload
def cdf(self, /, x: np.bool_ | np.uint8 | np.int8 | np.uint16 | np.int16 | np.float16 | np.float32) -> np.float32: ...
Expand All @@ -126,6 +127,7 @@ class _SimpleNormal:
def cdf(self, /, x: complex) -> np.complex128 | np.float64 | np.float32: ...
sf = cdf

@final
class _SimpleChi2:
df: int
def __init__(self, /, df: int) -> None: ...
Expand Down

0 comments on commit 4dd68a3

Please sign in to comment.