Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Literal type of engine argument incompatible with custom backends #6632

Closed
headtr1ck opened this issue May 23, 2022 · 5 comments · Fixed by #6651
Closed

Literal type of engine argument incompatible with custom backends #6632

headtr1ck opened this issue May 23, 2022 · 5 comments · Fixed by #6651

Comments

@headtr1ck
Copy link
Collaborator

What is your issue?

In the recent typing improvements the engine argument for open_dataset was changed from Str to a Literal of xarrays internal engines.
This will cause problems for all third party backend plugins.

We have several possibilities:

  1. I don't know if there is a way to know installed backends at type checking time. Then we could add this support. (I doubt this is possible seeing how dynamic these imports are)
  2. Is it possible for these plugins to tell type checkers that their engine is valid, i.e. change the type signature of xarrays function? Then we should add a how-to in the docu.
  3. Else we should probably revert to using Str.

Any typing experts here that could help?

@headtr1ck headtr1ck added the needs triage Issue that has not been reviewed by xarray team member label May 23, 2022
@TomNicholas TomNicholas added topic-backends topic-typing and removed needs triage Issue that has not been reviewed by xarray team member labels May 24, 2022
@TomNicholas
Copy link
Member

I don't think we should be using a Literal for something that a user is supposed to be able to extend anyway surely? IIUC a user is supposed to be define their own backend and use it to open a dataset, all without ever needing to add it to any official list within the xarray repo?

@TomNicholas
Copy link
Member

Or we could just have a global variable like
SUPPORTED_BACKENDS: List[str] = Literal['netcdf4', 'zarr']
which is appended to when a user registers a new backend?

@headtr1ck
Copy link
Collaborator Author

Or we could just have a global variable like
SUPPORTED_BACKENDS: List[str] = Literal['netcdf4', 'zarr']
which is appended to when a user registers a new backend?

If you know how that works statically, I don't see a way to do that.
You can only get dynamic content from static types and not the other way around.

@Illviljan
Copy link
Contributor

Yeah, reverting to Str seems to be the most straightforward way. It's unfortunate though Literals are really nice.

@headtr1ck
Copy link
Collaborator Author

Ok, let's keep this issue open for a bit in case someone still finds a solution.
But we should go back to Str before releasing the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants