Git Product home page Git Product logo

Comments (17)

aurelg avatar aurelg commented on September 2, 2024 1

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.

danymat avatar danymat commented on September 2, 2024 1

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.

equalis3r avatar equalis3r commented on September 2, 2024 1

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.

meijieru avatar meijieru commented on September 2, 2024 1

Problem solved on latest commit, thanks!

from neogen.

danymat avatar danymat commented on September 2, 2024

Hello, this seems to be fixed, can you try it ?

from neogen.

danymat avatar danymat commented on September 2, 2024

There are still some inconsistencies, I'm trying to fix them

from neogen.

danymat avatar danymat commented on September 2, 2024

Python should be okay now

from neogen.

aurelg avatar aurelg commented on September 2, 2024

Using a03cbd1 here, same issue:

def foo(bar: str) -> int:
    """
    	bar (str): 
    """
    pass

What would you need for me to help? :-)

from neogen.

danymat avatar danymat commented on September 2, 2024

Hello @aurelg, can yo try again ? I think I fixed it !

from neogen.

danymat avatar danymat commented on September 2, 2024

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.

aurelg avatar aurelg commented on September 2, 2024

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 and good_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 as mypy or pyright

That being said, having typed returns would be the cherry on the cake: a nice improvement, but certainly not mandatory 😊

from neogen.

equalis3r avatar equalis3r commented on September 2, 2024

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.

danymat avatar danymat commented on September 2, 2024

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.

danymat avatar danymat commented on September 2, 2024

So the signature hint should override the return statements in the code (if any) ?

from neogen.

aurelg avatar aurelg commented on September 2, 2024

I'd say so, yes :-)

from neogen.

meijieru avatar meijieru commented on September 2, 2024

Currently, it directly says Language python not supported lol.

from neogen.

danymat avatar danymat commented on September 2, 2024

Hmm can you try closing neovim and going again on the file ? If it does not work, press :e

from neogen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.