Skip to content

Use type hints for returned objects #864

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

Closed
alixdamman opened this issue Apr 23, 2020 · 3 comments
Closed

Use type hints for returned objects #864

alixdamman opened this issue Apr 23, 2020 · 3 comments
Assignees
Milestone

Comments

@alixdamman
Copy link
Collaborator

Now we officially do no longer support Python versions under 3.6, it is (maybe) the right time to introduce type hints the code of LArray.

@gdementen
Copy link
Contributor

It is a good idea to at least experiment with this but I wonder how to avoid duplication with what we have in the docstrings. Do you have an example of project using numpydoc style docstrings also using type hints?

Assuming we go down that path (this needs a bit of research before we decide), I wonder what is the best strategy: all at once (a very large task) or as we go.

@alixdamman
Copy link
Collaborator Author

alixdamman commented Apr 23, 2020

The idea behind is to (as for the ConstrainedSession, see #832) enable auto-completion on PyCharm. When users write something like:

arr = ndtest((3, 3)).transpose()
arr.

PyCharm doesn't know that the tranpose() method returns an array and then writing arr. below the call to transpose() doesn't make PyCharm to propose any auto-completion on Array's methods.

In other words, I am mostly interested to specify the type of the returned object by a method than to specify the type of each argument.

It is a good idea to at least experiment with this but I wonder how to avoid duplication with what we have in the docstrings. Do you have an example of project using numpydoc style docstrings also using type hints?

xarray partly does (for the returned type ;) ): https://github.com/pydata/xarray/blob/c788ee44008cdd65c8b6de40c737f1b28e173496/xarray/core/variable.py#L65

I don't know about pandas but they have a typing.py module.

Assuming we go down that path (this needs a bit of research before we decide), I wonder what is the best strategy: all at once (a very large task) or as we go.

We can start with the type of the returned object if there is one. In that case, I can try to do it for all functions and methods.

@gdementen
Copy link
Contributor

Ok, I missed that relatively recent development of things. It seems like the community is moving towards type hints in addition to numpydoc style docstrings. As you say, the return type is the most important and less verbose change, so we can start with that.

@alixdamman alixdamman modified the milestones: 0.34, 0.33 Jun 18, 2020
@alixdamman alixdamman changed the title Use type hints? Use type hints for returned objects Jun 18, 2020
alixdamman added a commit to alixdamman/larray that referenced this issue Jun 18, 2020
alixdamman added a commit to alixdamman/larray that referenced this issue Jun 19, 2020
alixdamman added a commit to alixdamman/larray that referenced this issue Jun 19, 2020
alixdamman added a commit to alixdamman/larray that referenced this issue Jun 24, 2020
alixdamman added a commit to alixdamman/larray that referenced this issue Jun 24, 2020
alixdamman added a commit to alixdamman/larray that referenced this issue Jun 24, 2020
alixdamman added a commit to alixdamman/larray that referenced this issue Jun 24, 2020
alixdamman added a commit to alixdamman/larray that referenced this issue Jun 24, 2020
alixdamman added a commit to alixdamman/larray that referenced this issue Jun 24, 2020
alixdamman added a commit to alixdamman/larray that referenced this issue Jun 24, 2020
alixdamman added a commit to alixdamman/larray that referenced this issue Jun 25, 2020
alixdamman added a commit to alixdamman/larray that referenced this issue Jun 25, 2020
alixdamman added a commit to alixdamman/larray that referenced this issue Jun 26, 2020
alixdamman added a commit to alixdamman/larray that referenced this issue Jun 30, 2020
…unctions and methods.

fix larray-project#867 : adapted code and configuration files to use mypy
alixdamman added a commit to alixdamman/larray that referenced this issue Jun 30, 2020
…unctions and methods.

fix larray-project#867 : adapted code and configuration files to use mypy
alixdamman added a commit to alixdamman/larray that referenced this issue Mar 2, 2021
…unctions and methods.

fix larray-project#867 : adapted code and configuration files to use mypy
@gdementen gdementen modified the milestones: 0.33, 0.34 Aug 17, 2021
alixdamman added a commit to alixdamman/larray that referenced this issue Sep 20, 2021
alixdamman added a commit to alixdamman/larray that referenced this issue Sep 27, 2021
alixdamman added a commit to alixdamman/larray that referenced this issue Sep 28, 2021
alixdamman added a commit that referenced this issue Sep 28, 2021
…turned type of the decorated function (issue #864)
alixdamman added a commit to alixdamman/larray that referenced this issue Oct 1, 2021
alixdamman added a commit to alixdamman/larray that referenced this issue Oct 4, 2021
gdementen pushed a commit to gdementen/larray that referenced this issue Nov 30, 2021
gdementen pushed a commit to gdementen/larray that referenced this issue Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants