-
Notifications
You must be signed in to change notification settings - Fork 30
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
Include arguments with asterik, fix issues with type hinting #22
base: master
Are you sure you want to change the base?
Conversation
Would be great to have this in |
Would also be great to have the type hints included in the docstring, so that when you do
you get
|
Thanks for the PR. It looks good to me on first glance but I'll just run tests once and then merge it. Also, I do want to add support for type hints but I am myself don't use type hints much yet so this has been pending for a while. |
There are still a few issues. Most importantly, this solution doesn't recognize import typing
def foo(a: typing.Union[str, int]) -> typing.Union[str, int]:
return a I will add a workaround in the next days. |
I'd love to implement that, but my Lisp skills are not sufficient to solve that in a reasonable time frame. If you happen to have a good starting point in the code though, let me know. |
I pushed some changes so more complex type hints involving brackets and brackets in brackets are recognized properly by from typing import Union
def a_function(arg0: Union[str, list[list[int]], arg1: Union[int, list]) -> None:
return None There were two issues:
The second commit seems to work as expected. After def a_function(arg0: Union[str, list[list[int]], arg1: Union[int, list]) -> None:
"""DESCRIBE FUNCTION HERE...
:param arg0:
:param arg1:
:returns:
"""
return None Additionally, I added a variable that makes it possible to remove Lastly, I included a fix to ignore a non-existing parameter when there is a trailing comma at the end of a multiline definition as in: def another_function(arg0,
arg1,
) -> None:
return None The result should now be: def another_function(arg0,
arg1,
) -> None:
"""DESCRIBE FUNCTION HERE...
:param arg0:
:param arg1:
:returns:
"""
return None instead of: def another_function(arg0,
arg1,
) -> None:
"""DESCRIBE FUNCTION HERE...
:param arg0:
:param arg1:
:param :
:returns:
"""
return None |
Accidentally closed. |
@kbeismann I've made some changes in my fork that allow for parsing of hint types. I don't have your nice feature of having rtype be optional. Perhaps you could combine our two diffs to get one that encapsulates it all? It also looks like you might have thought about some edge cases that would break my regex. For example, I don't think the trailing comma is allowed by my regex. It would be good to write some tests for this, but I haven't gotten around to it yet. |
Also ignore empty arguments.
Fix regular expression for type hinting involving square brackets in square brackets. Also modify docstring of sphinx-doc-fndef->doc.
tried this, it works great. thanks @kbeismann it would be great to have this in the main branch. |
@yitang Great if this works for you. I noticed that a few corner cases are still not covered and I should list them somewhere. Sadly, I neglected implementing these fixes with the test suit in mind. I'd like to rectify that but I'm not yet familiar with test-driven development in Elisp. |
Hi @kbeismann, Thanks for the PR and sorry for the late response. I am catching up with all the open PRs in this repo. It looks like there are multiple PRs for adding/handling type hints. I think it will be easier for me to merge PR #23 and #27 first and then cherry-pick the "include arguments with asterix" related commits from this one. I understand there are some edge cases regarding type hints that aren't covered in either PRs. Those can be fixed later. What do you think? |
Hi @naiquevin, Sounds good, I'd like to implement it test-based as proposed by @peterewills but haven't gotten around to it. I'll create another branch for that after you merged #23 and #27 into master I'd say.
Yeah, sadly there are still some cases that are not covered yet. We can deal with those later (by extending the tests). |
I added a variable that toggles the inclusion of arguments with an asterik, like
*args
or**kwargs
.At the moment, type hinting breaks the
sphinx-doc
function. I modified the regex strings to make them ignore hints while still giving the expected output.