Uh oh!
There was an error while loading. Please reload this page.
Initialize custom backends in open_dataset - #5684
Conversation
Illviljan
commented
Aug 8, 2021
I noticed this issue because my local mypy version was complaining about: Anyone have any ideas why the CI version doesn't complain about this? |
The original test function did not have any typing defined. For mypy to do any signature checking either of the inputs or outputs needs to be typed. This will throw the supertype error, uncomment importnumpyasnpimportxarrayasxrfromxarray.backendsimportBackendEntrypointexpected=xr.Dataset(
dict(a=2*np.arange(5)), coords=dict(x=("x", np.arange(5), dict(units="s")))
)
classCustomBackend(BackendEntrypoint):
defopen_dataset(
# self,filename_or_obj,
drop_variables=None,
**kwargs,
) ->xr.Dataset:
returnexpected.copy(deep=True) |
keewis
commented
Sep 20, 2021
This looks ready to me, and I think we should merge soon. |
* Test using correct signature * Initialize the class like in build_engine * Update whats-new.rst * Update whats-new.rst * Add back self to classes * Add some typing to the test, mypy should fail * mypy failed as expected, should not now Co-authored-by: keewis <keewis@users.noreply.github.com>
The backend classes are initialized in the
build_enginefunction:xarray/xarray/backends/plugins.py
Line 93 in 8b95da8
This wasn't the case for custom backends:
xarray/xarray/backends/plugins.py
Line 161 in 8b95da8
This PR initializes the engine, fixes the incorrect signature in the test (#5033) and reverts the doc changes done in #5532.
pre-commit run --all-fileswhats-new.rst