Skip to content
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

bug: python return annotations #51

Closed
quantum-booty opened this issue Jan 29, 2022 · 11 comments
Closed

bug: python return annotations #51

quantum-booty opened this issue Jan 29, 2022 · 11 comments
Labels
under review Waiting for review by users or developer.

Comments

@quantum-booty
Copy link

quantum-booty commented Jan 29, 2022

class Test:
  def __str__(self) -> str:
      """
  
      Parameters
      ----------
      self: 
          
  
      Returns
      -------
      config_str : 
          
      strip : 
          
      """
      config_str = ""
      for row in self.tile:
          row_str = "".join(row)
          config_str += row_str + "\n"
      return config_str.strip()

return config_str.strip() should be anonymous, and the self should not be a parameter, as it is a method.
This is what I expect:

class Test:
  def __str__(self) -> str:
      """
      Returns
      -------
      str:
          
      """
      config_str = ""
      for row in self.tile:
          row_str = "".join(row)
          config_str += row_str + "\n"
      return config_str.strip()
@danymat danymat added the bug Something isn't working label Jan 29, 2022
@danymat
Copy link
Owner

danymat commented Jan 29, 2022

Related: #41 (comment)

danymat added a commit that referenced this issue Jan 29, 2022
@danymat
Copy link
Owner

danymat commented Jan 29, 2022

I think I just added support for type hints, and fixed the bug at the same time
Can you try it out ?

@quantum-booty
Copy link
Author

quantum-booty commented Jan 29, 2022

Thanks a lot @danymat!
This is what I'm getting, I think self should not be a parameter

    def __str__(self) -> str:
        """

        Parameters
        ----------
        self: 
        	

        Returns
        -------
        str
        	
        """
        config_str = ""
        for row in self.tile:
            row_str = "".join(row)
            config_str += row_str + "\n"
        return config_str.strip()

@quantum-booty
Copy link
Author

I think the point about self should also apply to classmethods

    @classmethod
    def test(cls) -> None:
        """

        Parameters
        ----------
        cls: 
        	

        Returns
        -------
        None
        	
        """
        pass

I expect that cls should not be a parameter.

@quantum-booty
Copy link
Author

quantum-booty commented Jan 29, 2022

Also I think -> None should not generate a return type, because that is the default value thats being returned by a function.
So rather than this:

def test(a: int) -> None:
    """

    Parameters
    ----------
    a: int
    	

    Returns
    -------
    int
    	
    None
    	
    """
    pass

I don't expect it to generate a doc for None returns.

def test(a: int) -> None:
    """

    Parameters
    ----------
    a: int

    """
    pass

@danymat
Copy link
Owner

danymat commented Jan 29, 2022

  • None should now be hidden
  • reference to self is now removed

@danymat
Copy link
Owner

danymat commented Jan 29, 2022

I think the point about self should also apply to classmethods

    @classmethod
    def test(cls) -> None:
        """

        Parameters
        ----------
        cls: 
        	

        Returns
        -------
        None
        	
        """
        pass

I expect that cls should not be a parameter.

This seems to be a little bit difficult to do, I don't think I will do it tonight

@danymat
Copy link
Owner

danymat commented Jan 30, 2022

Hello, I think that commit d46c438 did provide a very great handling of such self, clscases. Can you take a look and try again ?

@danymat danymat added under review Waiting for review by users or developer. and removed bug Something isn't working labels Jan 30, 2022
@quantum-booty
Copy link
Author

class Test:
    @staticmethod
    def test2(a: int, b: str):
        """

        Parameters
        ----------
        a: int
            
        b: str
            

        Returns
        -------
        int
            
        str
            
        """
        pass
        

    @classmethod
    def test(cls, a: int, b: str):
        """

        Parameters
        ----------
        a: int
            
        b: str
            

        Returns
        -------
        int
            
        str
            
        """
        pass
        

    def test1(self, a: int, b: str):
        """

        Parameters
        ----------
        a: int
            
        b: str
            

        Returns
        -------
        int
            
        str
            
        """
        pass
       

Thanks @danymat I think that did fix the self and cls cases.
I think I've found another bug, some how its generating return int and str types.

danymat added a commit that referenced this issue Jan 30, 2022
@danymat
Copy link
Owner

danymat commented Jan 30, 2022

Last commit should fix it, a single line that did this lol. Is everything ok ?

@quantum-booty
Copy link
Author

nice xD good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
under review Waiting for review by users or developer.
Projects
None yet
Development

No branches or pull requests

2 participants