1

Hello StackOverflow Community,

Pycharm was giving me a suggestion to make a method static. I know that I don't want to do this.

My code was something along the lines of...

def myClassMethod(self) -> None:
    """
    PyCharm wants this function to be static, but I don't.
    """
    myOtherMethod('A string')
    myOtherMethod('A string')

def myOtherMethod(self, a_str: str) -> None:
    """
    This method takes in a string and prints it.
    """
    print(a_str)

I don't want the error in PyCharm (cause I am sort of a perfectionist, also because I don't want this false-positive) so can I legally change myClassMethod to something like:

def myClassMethod(self) -> None:
    """
    PyCharm wants this function to be static, but I don't.
    """
    myOtherMethod(self, 'A string')
    myOtherMethod(self, 'A string')

so that PyCharm sees that I've used self in the body of the method? Does calling self explicitly like this effect readability or make it less pythonic?

I have seen another suggestion to place a do_nothing function in the class that simply passes, but this seems like it pollutes the class namespace with a useless function just to get rid of a minor suggestion. Not worth it.

Community
  • 1
  • 1
boymeetscode
  • 805
  • 1
  • 9
  • 26
  • you mean self.myOtherMethod( 'A string') – Joe Bourne Feb 08 '17 at 22:45
  • Yeah, I'm still getting used to python and PyCharm. Don't quite understand why it wouldn't just give me a full blown error of something like, "Method doesn't exist" instead of a suggestion to make the method static. I got it shortly after posting and forgot to submit the solution. Thank you though. – boymeetscode Feb 13 '17 at 15:23

0 Answers0