Consistent with @jolvi, @ArundasR and others, the warning occurs in a member function that does not use self .
If you are sure that PyCharm is wrong, the function should not be @staticmethod , and if you set zero warnings, you can do this in one of two ways:
Workaround number 1
def bar(self): self.is_not_used() doing_something_without_self() def is_not_used(self): pass
Workaround # 2 [Thanks @ DavidPärsson ]
The application I had for this (the reason I could not use @staticmethod) was to create a handler table to respond to the protocol subtype field. All handlers must be of the same shape (static or non-static). But some failed to do anything with this instance. If I made these static, I would get a "TypeError: staticmethod object" cannot be called. "
In support of the OP's concern, inviting you to add a staticmethod whenever you can goes against the principle that it is easier to make the code less restrictive later than to make it more - creating a static method makes it less strict, since you can call class.f () instead of instance.f ().
Guess why this warning exists:
- He advertises a staticmethod . This makes developers aware of what they might intend.
- As @JohnWorrall points out, this gets your attention when I was accidentally left with this feature.
- It is a river for rethinking the object model; perhaps the function does not belong in this class at all.
BobStein-VisiBone Aug 03 '15 at 13:27 2015-08-03 13:27
source share