html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue https://github.com/pydata/xarray/issues/4054#issuecomment-778628502,https://api.github.com/repos/pydata/xarray/issues/4054,778628502,MDEyOklzc3VlQ29tbWVudDc3ODYyODUwMg==,32801740,2021-02-13T14:40:51Z,2021-02-13T14:40:51Z,CONTRIBUTOR,"I have implemented a possible solution to have typing for all unary and binary operators which works for mypy and also displays correctly inferred type hints on hovering over the code in Pylance (with VS Code) and PyCharm. The approach involves generating a stub file using a simple helper script. I'll open a draft PR so you can see this approach and for soliciting feedback. I have been experimenting with all kinds of other approaches to solve this issue but this was the only one with a satisfactory result. For reference, and jotting down from memory, I think I tried the following approaches without much success: - add the typing information to the ``not_implemented`` function in https://github.com/pydata/xarray/blob/971bad7c21551f297d3e1e24e3779488ea1b9565/xarray/core/arithmetic.py#L83-L105 - adding type declarations in a Generic mixin class parameterized on the return type of the methods. This doesn't handle dependencies of the return type on the type of the second argument of binary operators. - adding type declarations in a Generic mixin class parameterized on a Callback Protocol (PEP 544). This is too much magic for typing tools to grasp. - adding type declarations directly using a Callback Protocol. This seems to works fine for regular function but for methods the type of self of the class implementing the Protocol gets confused with the type of self in the Protocol itself. - using an overloaded abstract method for one operator (and then assigning the method to the dunders of all other operators to avoid a lot of repetition) results in mypy errors because it does not recognize that the concrete implementations are added dynamically. Making them concrete and returning NotImplemented doesn't work as type checkers are not sufficiently aware of the fallback logic of calling the corresponding reflexive method on the other argument of the binary operation. And raising causes some type checkers to think NoReturn is the intended return type.","{""total_count"": 1, ""+1"": 1, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,617140674 https://github.com/pydata/xarray/issues/4054#issuecomment-678679364,https://api.github.com/repos/pydata/xarray/issues/4054,678679364,MDEyOklzc3VlQ29tbWVudDY3ODY3OTM2NA==,5635139,2020-08-22T19:03:54Z,2020-08-22T19:03:54Z,MEMBER,"Given these are generated dynamically, is there a clever way to define types for these in Python? Or we have to write out all the methods? https://github.com/pydata/xarray/blob/v0.16.0/xarray/core/ops.py#L312-L316","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,617140674 https://github.com/pydata/xarray/issues/4054#issuecomment-678423562,https://api.github.com/repos/pydata/xarray/issues/4054,678423562,MDEyOklzc3VlQ29tbWVudDY3ODQyMzU2Mg==,10819524,2020-08-21T18:16:16Z,2020-08-21T18:16:16Z,CONTRIBUTOR,"Just dicsovered that the same things is true for `~`. Another thing to add to the list: ```... : error: Unsupported operand type for ~ (""DataArray"") [operator]```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,617140674 https://github.com/pydata/xarray/issues/4054#issuecomment-678369742,https://api.github.com/repos/pydata/xarray/issues/4054,678369742,MDEyOklzc3VlQ29tbWVudDY3ODM2OTc0Mg==,2448579,2020-08-21T16:07:20Z,2020-08-21T16:07:20Z,MEMBER,"Yeah there's no type info in `DataArray._binary_op`, `Variable._binary_op` and `Dataset._binary_op`","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,617140674 https://github.com/pydata/xarray/issues/4054#issuecomment-677920840,https://api.github.com/repos/pydata/xarray/issues/4054,677920840,MDEyOklzc3VlQ29tbWVudDY3NzkyMDg0MA==,10819524,2020-08-20T21:41:51Z,2020-08-20T22:48:49Z,CONTRIBUTOR,"We're currently working on a library largely based on xarray and have seen the same types of errors from mypy (PR in our project that is currently trying to integrate mypy: https://github.com/Ouranosinc/xclim/pull/532). Currently working off of xarray v0.16. I also want to note this error is raised for other operations as well (`+`, `-`, `/`, and `*`) between `xarray.DataArray` and `xarray.Datasets`. ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,617140674 https://github.com/pydata/xarray/issues/4054#issuecomment-677944214,https://api.github.com/repos/pydata/xarray/issues/4054,677944214,MDEyOklzc3VlQ29tbWVudDY3Nzk0NDIxNA==,5635139,2020-08-20T22:47:49Z,2020-08-20T22:47:49Z,MEMBER,"Yes, this looks like incomplete typing. We would take a PR for these for sure.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,617140674