8000 Merge pull request #28170 from jorenham/typing/fix-exports · melissawm/numpy@18ea55b · GitHub
[go: up one dir, main page]

Skip to content

Commit 18ea55b

Browse files
authored
Merge pull request numpy#28170 from jorenham/typing/fix-exports
TYP: Fix missing and spurious top-level exports
2 parents 4fe02b1 + e0093da commit 18ea55b

File tree

2 files changed

+61
-38
lines changed

2 files changed

+61
-38
lines changed

numpy/__init__.pyi

Lines changed: 61 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# ruff: noqa: I001
12
import builtins
23
import sys
34
import mmap
@@ -206,17 +207,19 @@ else:
206207
)
207208

208209
from typing import (
209-
Literal as L,
210210
Any,
211+
ClassVar,
212+
Final,
213+
Generic,
214+
Literal as L,
211215
NoReturn,
212216
SupportsComplex,
213217
SupportsFloat,
214218
SupportsInt,
215219
SupportsIndex,
216-
Final,
217-
final,
218-
ClassVar,
219220
TypeAlias,
221+
TypedDict,
222+
final,
220223
type_check_only,
221224
)
222225

@@ -225,11 +228,13 @@ from typing import (
225228
# library include `typing_extensions` stubs:
226229
# https://github.com/python/typeshed/blob/main/stdlib/typing_extensions.pyi
227230
from _typeshed import StrOrBytesPath, SupportsFlush, SupportsLenAndGetItem, SupportsWrite
228-
from typing_extensions import CapsuleType, Generic, LiteralString, Never, Protocol, Self, TypeVar, Unpack, deprecated, overload
231+
from typing_extensions import CapsuleType, LiteralString, Never, Protocol, Self, TypeVar, Unpack, deprecated, overload
229232

230233
from numpy import (
234+
char,
231235
core,
232236
ctypeslib,
237+
dtypes,
233238
exceptions,
234239
f2py,
235240
fft,
@@ -238,15 +243,22 @@ from numpy import (
238243
ma,
239244
polynomial,
240245
random,
241-
testing,
242-
typing,
243-
version,
244-
dtypes,
245246
rec,
246-
char,
247247
strings,
248+
testing,
249+
typing,
248250
)
249251

252+
# available through `__getattr__`, but not in `__all__` or `__dir__`
253+
from numpy import (
254+
__config__ as __config__,
255+
matlib as matlib,
256+
matrixlib as matrixlib,
257+
version as version,
258+
)
259+
if sys.version_info < (3, 12):
260+
from numpy import distutils as distutils
261+
250262
from numpy._core.records import (
251263
record,
252264
recarray,
@@ -440,6 +452,7 @@ from numpy.lib._arraypad_impl import (
440452

441453
from numpy.lib._arraysetops_impl import (
442454
ediff1d,
455+
in1d,
443456
intersect1d,
444457
isin,
445458
setdiff1d,
@@ -481,14 +494,15 @@ from numpy.lib._function_base_impl import (
481494
bartlett,
482495
blackman,
483496
kaiser,
497+
trapezoid,
498+
trapz,
484499
i0,
485500
meshgrid,
486501
delete,
487502
insert,
488503
append,
489504
interp,
490505
quantile,
491-
trapezoid,
492506
)
493507

494508
from numpy.lib._histograms_impl import (
@@ -627,13 +641,10 @@ from numpy.matrixlib import (
627641
bmat,
628642
)
629643

630-
__all__ = [
631-
"emath", "show_config", "version", "__version__", "__array_namespace_info__",
632-
644+
__all__ = [ # noqa: RUF022
633645
# __numpy_submodules__
634-
"linalg", "fft", "dtypes", "random", "polynomial", "ma", "exceptions", "lib",
635-
"ctypeslib", "testing", "test", "rec", "char", "strings",
636-
"core", "typing", "f2py",
646+
"char", "core", "ctypeslib", "dtypes", "exceptions", "f2py", "fft", "lib", "linalg",
647+
"ma", "polynomial", "random", "rec", "strings", "test", "testing", "typing",
637648

638649
# _core.__all__
639650
"abs", "acos", "acosh", "asin", "asinh", "atan", "atanh", "atan2", "bitwise_invert",
@@ -651,8 +662,8 @@ __all__ = [
651662
"tensordot", "little_endian", "fromiter", "array_equal", "array_equiv", "indices",
652663
"fromfunction", "isclose", "isscalar", "binary_repr", "base_repr", "ones",
653664
"identity", "allclose", "putmask", "flatnonzero", "inf", "nan", "False_", "True_",
654-
"bitwise_not", "full", "full_like", "matmul", "vecdot", "shares_memory",
655-
"may_share_memory", "_get_promotion_state", "_set_promotion_state",
665+
"bitwise_not", "full", "full_like", "matmul", "vecdot", "vecmat",
666+
"shares_memory", "may_share_memory",
656667
"all", "amax", "amin", "any", "argmax", "argmin", "argpartition", "argsort",
657668
"around", "choose", "clip", "compress", "cumprod", "cumsum", "cumulative_prod",
658669
"cumulative_sum", "diagonal", "mean", "max", "min", "matrix_transpose", "ndim",
@@ -667,7 +678,7 @@ __all__ = [
667678
"frompyfunc", "gcd", "greater", "greater_equal", "heaviside", "hypot", "invert",
668679
"isfinite", "isinf", "isnan", "isnat", "lcm", "ldexp", "left_shift", "less",
669680
"less_equal", "log", "log10", "log1p", "log2", "logaddexp", "logaddexp2",
670-
"logical_and", "logical_not", "logical_or", "logical_xor", "maximum", "minimum",
681+
"logical_and", "logical_not", "logical_or", "logical_xor", "matvec", "maximum", "minimum",
671682
"mod", "modf", "multiply", "negative", "nextafter", "not_equal", "pi", "positive",
672683
"power", "rad2deg", "radians", "reciprocal", "remainder", "right_shift", "rint",
673684
"sign", "signbit", "sin", "sinh", "spacing", "sqrt", "square", "subtract", "tan",
@@ -686,7 +697,7 @@ __all__ = [
686697
"array2string", "array_str", "array_repr", "set_printoptions", "get_printoptions",
687698
"printoptions", "format_float_positional", "format_float_scientific", "require",
688699
"seterr", "geterr", "setbufsize", "getbufsize", "seterrcall", "geterrcall",
689-
"errstate", "_no_nep50_warning",
700+
"errstate",
690701
# _core.function_base.__all__
691702
"logspace", "linspace", "geomspace",
692703
# _core.getlimits.__all__
@@ -696,21 +707,21 @@ __all__ = [
696707
"vstack",
697708
# _core.einsumfunc.__all__
698709
"einsum", "einsum_path",
699-
710+
# matrixlib.__all__
711+
"matrix", "bmat", "asmatrix",
700712
# lib._histograms_impl.__all__
701713
"histogram", "histogramdd", "histogram_bin_edges",
702714
# lib._nanfunctions_impl.__all__
703715
"nansum", "nanmax", "nanmin", "nanargmax", "nanargmin", "nanmean", "nanmedian",
704716
"nanpercentile", "nanvar", "nanstd", "nanprod", "nancumsum", "nancumprod",
705717
"nanquantile",
706718
# lib._function_base_impl.__all__
707-
# NOTE: `trapz` is omitted because it is deprecated
708719
"select", "piecewise", "trim_zeros", "copy", "iterable", "percentile", "diff",
709720
"gradient", "angle", "unwrap", "sort_complex", "flip", "rot90", "extract", "place",
710721
"vectorize", "asarray_chkfinite", "average", "bincount", "digitize", "cov",
711722
"corrcoef", "median", "sinc", "hamming", "hanning", "bartlett", "blackman",
712-
"kaiser", "i0", "meshgrid", "delete", "insert", "append", "interp", "quantile",
713-
"trapezoid",
723+
"kaiser", "trapezoid", "trapz", "i0", "meshgrid", "delete", "insert", "append",
724+
"interp", "quantile",
714725
# lib._twodim_base_impl.__all__
715726
"diag", "diagflat", "eye", "fliplr", "flipud", "tri", "triu", "tril", "vander",
716727
"histogram2d", "mask_indices", "tril_indices", "tril_indices_from", "triu_indices",
@@ -724,9 +735,8 @@ __all__ = [
724735
"iscomplexobj", "isrealobj", "imag", "iscomplex", "isreal", "nan_to_num", "real",
725736
"real_if_close", "typename", "mintypecode", "common_type",
726737
# lib._arraysetops_impl.__all__
727-
# NOTE: `in1d` is omitted because it is deprecated
728-
"ediff1d", "intersect1d", "isin", "setdiff1d", "setxor1d", "union1d", "unique",
729-
"unique_all", "unique_counts", "unique_inverse", "unique_values",
738+
"ediff1d", "in1d", "intersect1d", "isin", "setdiff1d", "setxor1d", "union1d",
739+
"unique", "unique_all", "unique_counts", "unique_inverse", "unique_values",
730740
# lib._ufunclike_impl.__all__
731741
"fix", "isneginf", "isposinf",
732742
# lib._arraypad_impl.__all__
@@ -746,9 +756,9 @@ __all__ = [
746756
"index_exp", "ix_", "ndenumerate", "ndindex", "fill_diagonal", "diag_indices",
747757
"diag_indices_from",
748758

749-
# matrixlib.__all__
750-
"matrix", "bmat", "asmatrix",
751-
]
759+
# __init__.__all__
760+
"emath", "show_config", "__version__", "__array_namespace_info__",
761+
] # fmt: skip
752762

753763
### Constrained types (for internal use only)
754764
# Only use these for functions; never as generic type parameter.
@@ -1047,6 +1057,16 @@ _IntTD64Unit: TypeAlias = L[_MonthUnit, _IntTimeUnit]
10471057
_TD64Unit: TypeAlias = L[_DateUnit, _TimeUnit]
10481058
_TimeUnitSpec: TypeAlias = _TD64UnitT | tuple[_TD64UnitT, SupportsIndex]
10491059

1060+
### TypedDict's (for internal use only)
1061+
1062+
@type_check_only
1063+
class _FormerAttrsDict(TypedDict):
1064+
object: LiteralString
1065+
float: LiteralString
1066+
complex: LiteralString
1067+
str: LiteralString
1068+
int: LiteralString
1069+
10501070
### Protocols (for internal use only)
10511071

10521072
@type_check_only
@@ -1147,22 +1167,26 @@ class _IntegralMixin(_RealMixin):
11471167
### Public API
11481168

11491169
__version__: Final[LiteralString] = ...
1150-
__array_api_version__: Final = "2023.12"
1151-
test: Final[PytestTester] = ...
11521170

11531171
e: Final[float] = ...
11541172
euler_gamma: Final[float] = ...
1173+
pi: Final[float] = ...
11551174
inf: Final[float] = ...
11561175
nan: Final[float] = ...
1157-
pi: Final[float] = ...
1158-
11591176
little_endian: Final[builtins.bool] = ...
1160-
11611177
False_: Final[np.bool[L[False]]] = ...
11621178
True_: Final[np.bool[L[True]]] = ...
1163-
11641179
newaxis: Final[None] = None
11651180

1181+
# not in __all__
1182+
__NUMPY_SETUP__: Final[L[False]] = False
1183+
__numpy_submodules__: Final[set[LiteralString]] = ...
1184+
__expired_attributes__: Final[dict[LiteralString, LiteralString]]
1185+
__former_attrs__: Final[_FormerAttrsDict] = ...
1186+
__future_scalars__: Final[set[L["bytes", "str", "object"]]] = ...
1187+
__array_api_version__: Final[L["2023.12"]] = "2023.12"
1188+
test: Final[PytestTester] = ...
1189+
11661190
@final
11671191
class dtype(Generic[_SCT_co]):
11681192
names: None | tuple[builtins.str, ...]

numpy/typing/tests/data/fail/modules.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ np.math # E: Module has no attribute
1313
# e.g. one must first execute `import numpy.lib.recfunctions`
1414
np.lib.recfunctions # E: Module has no attribute
1515

179B
16-
np.__NUMPY_SETUP__ # E: Module has no attribute
1716
np.__deprecated_attrs__ # E: Module has no attribute
1817
np.__expired_functions__ # E: Module has no attribute

0 commit comments

Comments
 (0)
0