Comments (17)
Many thanks, Args:
is back where it should be!
def toto(name: str) -> int:
"""
Args:
name (str):
"""
pass
BTW, shouldn't Returns:
be here as well? 🤔
Edit: OK, nailed it: Returns:
is here when there's a return
statement in the function - I thought it would use type hints. My bad. Thanks for your work! 👍
from neogen.
BTW, shouldn't Returns: be here as well?
No, from the standards, Returns should only be here if there's a return type inside the function.
from neogen.
Here is an example that I can think of. Hope it can help.
- Function with only 1 return
def compare(param1: int, param2: int) -> bool:
"""Example function with types documented in the docstring.
Parameters
----------
param1 : int
The first parameter.
param2 : int
The second parameter.
Returns
-------
bool
True if successful, False otherwise.
"""
return param1 == param2
- Function with multiple returns
def valid_floor_div(param1: int, param2: int) -> Union[str, int]:
"""Example function with types documented in the docstring.
Parameters
----------
param1 : int
The first parameter.
param2 : int
The second parameter.
Returns
-------
Union[str, int]
str if non-zero division, int otherwise.
"""
if param2 == 0:
return "The divisor must be non-zero"
else:
return prama1 / param2
from neogen.
Problem solved on latest commit, thanks!
from neogen.
Hello, this seems to be fixed, can you try it ?
from neogen.
There are still some inconsistencies, I'm trying to fix them
from neogen.
Python should be okay now
from neogen.
Using a03cbd1 here, same issue:
def foo(bar: str) -> int:
"""
bar (str):
"""
pass
What would you need for me to help? :-)
from neogen.
Hello @aurelg, can yo try again ? I think I fixed it !
from neogen.
I thought it would use type hints
Hmm, it can, and should be relatively easy to do.
By the way, supporting type hints in return types can be a little problematic, when we have multiple returns in the function:
def test() -> int:
if 1:
return hello
else:
return good_bye
What would be the generated annotation for it ?
from neogen.
Good point.
My guess would be to stick to the type hint annotated in the function signature, i.e. int
, because:
- the function signature is already the source of truth for function parameters, it's quite consistent to have it for the returned type as well, and
- inferring the types of
hello
andgood_bye
, as well as their consistency with type hints both in the function signature or within its body, usually fall under the responsibility of a dedicated tool, such asmypy
orpyright
That being said, having typed returns would be the cherry on the cake: a nice improvement, but certainly not mandatory 😊
from neogen.
I agree with @aurelg The typehint in the function signature is the contract and mypy/pyright will detect if programmer violates such contract. Let's say hello type is int
and good_byte type is str
. To not be yelled at by mypy, my return in the function signature needs to be: Union[int, str]
or with python3.10 and above, int | str
. As long as the plugin parses the function signature correctly, it's the programmers' responsibility to write correct contracts.
from neogen.
That being said, having typed returns would be the cherry on the cake: a nice improvement, but certainly not mandatory 😊
I mean, it's possible, it's just that I don't know what is the desired output.
Can you guys provide me the desired annotation of the example function ?
from neogen.
So the signature hint should override the return statements in the code (if any) ?
from neogen.
I'd say so, yes :-)
from neogen.
Currently, it directly says Language python not supported
lol.
from neogen.
Hmm can you try closing neovim and going again on the file ? If it does not work, press :e
from neogen.
Related Issues (20)
- `Invalid 'end_col': out of range` error whenever running `Neogen file` HOT 2
- Bug: handling of arbitrary args and kwargs with type hints HOT 1
- Allow generating explicit sections HOT 3
- Update / Correction command HOT 2
- Python - raise module_name.Error() is not detected
- Bug: Neogen not functioning in vue files. HOT 2
- Could not get neogen to work with LazyVim HOT 4
- Need unittests HOT 1
- Missing blank line in numpydoc
- Option to always disable writing argument types in Python HOT 2
- FR: support creating annotations in Markdown code blocks HOT 1
- Sometimes native snippets do not expand on tab
- Add support for records in C# HOT 2
- Support annotating interfaces HOT 2
- Help implementing doctrings for Julia HOT 4
- Annotate all nodes in a file or ones from visual selection HOT 1
- Fix Python bugs
- Use Release Please to simplify neogen versioning
- Python: Should Raises be after Return in google style? HOT 1
- Error While Generating File Documents
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from neogen.