I’m developing in Python using PyDev in Eclipse, and some of my code generates errors in the code analysis tool. Specifically:
class Group(object):
def key(self, k):
class Subkey(object):
def __enter__(s):
self._settings.beginGroup(k)
return self
def __exit__(s, type, value, tb):
self._settings.endGroup()
return Subkey()
Gives me a "Method '__enter__- group' should have self as first parameter" error, and a similar error for __exit__. Is there a way to solve this without assigning self to another variable and reusing the variable in the other method signatures?
You could disable that error in the preferences…
Or refactor the code…
What else do you expect? The error checks are there to help you. If you don’t think they’re legitimate errors, disable them or refactor the code.
In this case I’d say refactor the code. It’s more readable, as evidenced by King Radical’s answer. He didn’t understand that
swas anotherself.