issue_comments
7 rows where author_association = "CONTRIBUTOR" and issue = 807764700 sorted by updated_at descending
This data as json, CSV (advanced)
Suggested facets: reactions, created_at (date), updated_at (date)
issue 1
- add typing to unary and binary arithmetic operators · 7 ✖
id | html_url | issue_url | node_id | user | created_at | updated_at ▲ | author_association | body | reactions | performed_via_github_app | issue |
---|---|---|---|---|---|---|---|---|---|---|---|
813277878 | https://github.com/pydata/xarray/pull/4904#issuecomment-813277878 | https://api.github.com/repos/pydata/xarray/issues/4904 | MDEyOklzc3VlQ29tbWVudDgxMzI3Nzg3OA== | rhkleijn 32801740 | 2021-04-05T08:41:24Z | 2021-04-05T08:41:24Z | CONTRIBUTOR | Thanks, there was one more minor merge artifact. Should be fixed now. |
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
add typing to unary and binary arithmetic operators 807764700 | |
799648923 | https://github.com/pydata/xarray/pull/4904#issuecomment-799648923 | https://api.github.com/repos/pydata/xarray/issues/4904 | MDEyOklzc3VlQ29tbWVudDc5OTY0ODkyMw== | rhkleijn 32801740 | 2021-03-15T18:27:18Z | 2021-03-15T19:01:07Z | CONTRIBUTOR |
done
I have tried that but PyCharm would not handle the
If we remove that line, it incorrectly infers the result of
Agreed that this is surprising behaviour. I suspect mypy might have something like an implicit internal rule to fallback to the type of the first operand of a binary operator. That would be consistent with the behaviours of both of the above cases.
I can relate to that. On the other hand, there may also be a pragmatic reason to go the extra mile. If we don't it may result in users thinking xarray's newly added typing is to blame for unexpected type inferences and reporting issues here. When at some point in the future these tools indeed do catch up it is straightforward to adapt the script and regenerate. |
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
add typing to unary and binary arithmetic operators 807764700 | |
798793062 | https://github.com/pydata/xarray/pull/4904#issuecomment-798793062 | https://api.github.com/repos/pydata/xarray/issues/4904 | MDEyOklzc3VlQ29tbWVudDc5ODc5MzA2Mg== | rhkleijn 32801740 | 2021-03-13T22:07:41Z | 2021-03-13T22:07:41Z | CONTRIBUTOR |
thanks!
It takes precedence only during type checking as the source for static type information. The generated
There seem to be quite some open issues here with no indication they currently are actively working on fixing them. I am not using PyCharm myself, but as it is widely used I would also expect quite some xarray users to be using it.
For these unary ops with simple type hints if would probably work but for most other methods with multiple overloads the typing ecosystem is not yet mature enough. In this issue I have commented on it. I hope one day we will be able to refactor this into some generic parent classes (one for unary ops, one for binary (and reflexive) ops and one for inplace ops) from which we can inherit. Using a generic parent class only for the unary ops and not for the others would make the script more complicated. For now, I'd say this somewhat low-tech solution gets the job done.
Unfortunately we have to define them both ways for typing purposes. This comment in Note: in some of the overloads below the return value in reality is NotImplemented,which cannot accurately be expressed with type hints,e.g. Literal[NotImplemented]or type(NotImplemented) are not allowed and NoReturn has a different meaning.In such cases we are lending the type checkers a hand by specifying the return typeof the corresponding reflexive method on
|
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
add typing to unary and binary arithmetic operators 807764700 | |
798771631 | https://github.com/pydata/xarray/pull/4904#issuecomment-798771631 | https://api.github.com/repos/pydata/xarray/issues/4904 | MDEyOklzc3VlQ29tbWVudDc5ODc3MTYzMQ== | rhkleijn 32801740 | 2021-03-13T19:24:08Z | 2021-03-13T19:25:00Z | CONTRIBUTOR | You can now view the branch I mentioned in my previous message at https://github.com/pydata/xarray/compare/master...rhkleijn:gen-ops . It would get rid of the need for dynamically generating (injecting) unary and binary operators at runtime. Note that its script generates both the module containing the arithmetic methods and its accompanying stub file. This setup turned out to be more robust than both:
In all cases mypy and pylance work nicely. I prefer the Also, I am not sure what to do with the |
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
add typing to unary and binary arithmetic operators 807764700 | |
790995670 | https://github.com/pydata/xarray/pull/4904#issuecomment-790995670 | https://api.github.com/repos/pydata/xarray/issues/4904 | MDEyOklzc3VlQ29tbWVudDc5MDk5NTY3MA== | rhkleijn 32801740 | 2021-03-04T22:39:14Z | 2021-03-04T22:39:14Z | CONTRIBUTOR |
Done
Locally it seems to work fine. Let's see what happens in CI now.
Not yet. I am working on generating the methods themselves on a local branch. It required changing all |
{ "total_count": 1, "+1": 1, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
add typing to unary and binary arithmetic operators 807764700 | |
779404893 | https://github.com/pydata/xarray/pull/4904#issuecomment-779404893 | https://api.github.com/repos/pydata/xarray/issues/4904 | MDEyOklzc3VlQ29tbWVudDc3OTQwNDg5Mw== | rhkleijn 32801740 | 2021-02-15T19:10:56Z | 2021-02-15T19:10:56Z | CONTRIBUTOR |
I agree. Both PRs you mention would be nice to see merged. I was still using numpy 1.19.
I usually prefer inline type hints. The motivation for stub files was mostly because all other approaches I tried where not sufficient, see my comment in #4054. It turns out we might not even need a stub file, see my reply above to max-sixty's comments.
That is correct. It can currently be considered a mixin class during type checking and a no-op at compile and runtime. If I can get max-sixty's suggestion to work, then we would quite literally be following up on that TODO by using mixin classes instead of the unintuitive "inject" functions.
Those are mypy warning for overlapping overload signatures with incompatible return types. In practice it is not a problem as the first matching overload gets picked. One reason for overlapping is that with numpy <=1.20
Agreed. What name would work in this case? Something like
I think it would be nice to allow some simple kinds of subclassing (some (many?) methods already preserve the subclass in the return value but the type hint mentions the base class as return type). The particular use case I have in mind involves having a custom Accessor registered with ``` import xarray as xr if TYPE_CHECKING: class Dataset(xr.Dataset): myaccessor: MyAccessor else: Dataset = xr.Dataset # note that at runtime we just work with xr.Dataset ds = Dataset(...) ds2 = (ds + 1).sel(x=1) # some operations (ideally preserving subclass!) In the line below I would like my IDE to be able to show me the docstrings,methods signatures and typing information for
|
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
add typing to unary and binary arithmetic operators 807764700 | |
779295725 | https://github.com/pydata/xarray/pull/4904#issuecomment-779295725 | https://api.github.com/repos/pydata/xarray/issues/4904 | MDEyOklzc3VlQ29tbWVudDc3OTI5NTcyNQ== | rhkleijn 32801740 | 2021-02-15T15:30:51Z | 2021-02-15T15:30:51Z | CONTRIBUTOR |
I did not consider it but that is a very promising idea. It is probably feasible to adapt the script to generate the methods themselves together with their type hints into a regular Python module instead of a stub file. I will give it a try this week. It would have the same disadvantage of needing the script for generating the file. There are several advantages: the stub file approach which may feel a bit odd would not even be necessary, it could replace the current injection logic, implementation and type hints would be in a single place and it could simplify the class hierarchy a bit.
The mypy documentation states that if a directory contains both a .py and a .pyi file for the same module, the .pyi file takes precedence. It is my understanding that stub files work on a file by file basis and you cannot mix them for a single file. There should be no interactions here, as a _typed_ops.py module doesn't even exist in this case, only the _typed_ops.pyi stub file. |
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
add typing to unary and binary arithmetic operators 807764700 |
Advanced export
JSON shape: default, array, newline-delimited, object
CREATE TABLE [issue_comments] ( [html_url] TEXT, [issue_url] TEXT, [id] INTEGER PRIMARY KEY, [node_id] TEXT, [user] INTEGER REFERENCES [users]([id]), [created_at] TEXT, [updated_at] TEXT, [author_association] TEXT, [body] TEXT, [reactions] TEXT, [performed_via_github_app] TEXT, [issue] INTEGER REFERENCES [issues]([id]) ); CREATE INDEX [idx_issue_comments_issue] ON [issue_comments] ([issue]); CREATE INDEX [idx_issue_comments_user] ON [issue_comments] ([user]);
user 1