Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2c0432b

Browse filesBrowse files
authored
Merge pull request #28178 from charris/backport-28170
TYP: Fix missing and spurious top-level exports
2 parents 2230a08 + b04e32c commit 2c0432b
Copy full SHA for 2c0432b

File tree

Expand file treeCollapse file tree

2 files changed

+61
-38
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+61
-38
lines changed

‎numpy/__init__.pyi

Copy file name to clipboardExpand all lines: numpy/__init__.pyi
+61-37Lines 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
@@ -1150,22 +1170,26 @@ class _IntegralMixin(_RealMixin):
11501170
### Public API
11511171

11521172
__version__: Final[LiteralString] = ...
1153-
__array_api_version__: Final = "2023.12"
1154-
test: Final[PytestTester] = ...
11551173

11561174
e: Final[float] = ...
11571175
euler_gamma: Final[float] = ...
1176+
pi: Final[float] = ...
11581177
inf: Final[float] = ...
11591178
nan: Final[float] = ...
1160-
pi: Final[float] = ...
1161-
11621179
little_endian: Final[builtins.bool] = ...
1163-
11641180
False_: Final[np.bool[L[False]]] = ...
11651181
True_: Final[np.bool[L[True]]] = ...
1166-
11671182
newaxis: Final[None] = None
11681183

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

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

Copy file name to clipboardExpand all lines: numpy/typing/tests/data/fail/modules.pyi
-1Lines 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

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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.