Skip to content

Commit e646dd9

Browse files
authored
hardcoded xarray.__all__ (#3703)
* Fix mypy --strict * isort * mypy version bump * trivial * testing.__all__ and ufuncs.__all__ * isort * Revert mypy version bump * Revert isort
1 parent 924c052 commit e646dd9

File tree

4 files changed

+123
-9
lines changed

4 files changed

+123
-9
lines changed

doc/whats-new.rst

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ Bug fixes
8787
- Fix a regression in :py:meth:`Dataset.drop`: allow passing any
8888
iterable when dropping variables (:issue:`3552`, :pull:`3693`)
8989
By `Justus Magin <https://github.com/keewis>`_.
90+
- Fixed errors emitted by ``mypy --strict`` in modules that import xarray.
91+
(:issue:`3695`) by `Guido Imperiale <https://github.com/crusaderky>`_.
9092

9193
Documentation
9294
~~~~~~~~~~~~~

xarray/__init__.py

+52-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
""" isort:skip_file """
2-
# flake8: noqa
32

43
from ._version import get_versions
54

@@ -42,3 +41,55 @@
4241
from . import testing
4342

4443
from .core.common import ALL_DIMS
44+
45+
# A hardcoded __all__ variable is necessary to appease
46+
# `mypy --strict` running in projects that import xarray.
47+
__all__ = (
48+
# Sub-packages
49+
"ufuncs",
50+
"testing",
51+
"tutorial",
52+
# Top-level functions
53+
"align",
54+
"apply_ufunc",
55+
"as_variable",
56+
"auto_combine",
57+
"broadcast",
58+
"cftime_range",
59+
"combine_by_coords",
60+
"combine_nested",
61+
"concat",
62+
"decode_cf",
63+
"dot",
64+
"full_like",
65+
"load_dataarray",
66+
"load_dataset",
67+
"map_blocks",
68+
"merge",
69+
"ones_like",
70+
"open_dataarray",
71+
"open_dataset",
72+
"open_mfdataset",
73+
"open_rasterio",
74+
"open_zarr",
75+
"register_dataarray_accessor",
76+
"register_dataset_accessor",
77+
"save_mfdataset",
78+
"set_options",
79+
"show_versions",
80+
"where",
81+
"zeros_like",
82+
# Classes
83+
"CFTimeIndex",
84+
"Coordinate",
85+
"DataArray",
86+
"Dataset",
87+
"IndexVariable",
88+
"Variable",
89+
# Exceptions
90+
"MergeError",
91+
"SerializationWarning",
92+
# Constants
93+
"__version__",
94+
"ALL_DIMS",
95+
)

xarray/testing.py

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
from xarray.core.indexes import default_indexes
1111
from xarray.core.variable import IndexVariable, Variable
1212

13+
__all__ = (
14+
"assert_allclose",
15+
"assert_chunks_equal",
16+
"assert_equal",
17+
"assert_identical",
18+
)
19+
1320

1421
def _decode_string_data(data):
1522
if data.dtype.kind == "S":

xarray/ufuncs.py

+62-8
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,68 @@ def _create_op(name):
132132
return func
133133

134134

135-
__all__ = """logaddexp logaddexp2 conj exp log log2 log10 log1p expm1 sqrt
136-
square sin cos tan arcsin arccos arctan arctan2 hypot sinh cosh
137-
tanh arcsinh arccosh arctanh deg2rad rad2deg logical_and
138-
logical_or logical_xor logical_not maximum minimum fmax fmin
139-
isreal iscomplex isfinite isinf isnan signbit copysign nextafter
140-
ldexp fmod floor ceil trunc degrees radians rint fix angle real
141-
imag fabs sign frexp fmod
142-
""".split()
135+
__all__ = ( # noqa: F822
136+
"angle",
137+
"arccos",
138+
"arccosh",
139+
"arcsin",
140+
"arcsinh",
141+
"arctan",
142+
"arctan2",
143+
"arctanh",
144+
"ceil",
145+
"conj",
146+
"copysign",
147+
"cos",
148+
"cosh",
149+
"deg2rad",
150+
"degrees",
151+
"exp",
152+
"expm1",
153+
"fabs",
154+
"fix",
155+
"floor",
156+
"fmax",
157+
"fmin",
158+
"fmod",
159+
"fmod",
160+
"frexp",
161+
"hypot",
162+
"imag",
163+
"iscomplex",
164+
"isfinite",
165+
"isinf",
166+
"isnan",
167+
"isreal",
168+
"ldexp",
169+
"log",
170+
"log10",
171+
"log1p",
172+
"log2",
173+
"logaddexp",
174+
"logaddexp2",
175+
"logical_and",
176+
"logical_not",
177+
"logical_or",
178+
"logical_xor",
179+
"maximum",
180+
"minimum",
181+
"nextafter",
182+
"rad2deg",
183+
"radians",
184+
"real",
185+
"rint",
186+
"sign",
187+
"signbit",
188+
"sin",
189+
"sinh",
190+
"sqrt",
191+
"square",
192+
"tan",
193+
"tanh",
194+
"trunc",
195+
)
196+
143197

144198
for name in __all__:
145199
globals()[name] = _create_op(name)

0 commit comments

Comments
 (0)