sourcery-ai / sourcery

Instant AI code reviews
https://sourcery.ai
MIT License
1.54k stars 68 forks source link

False positive `instance-method-first-arg-name` when using `zope.interface` #380

Open miketheman opened 1 year ago

miketheman commented 1 year ago

Checklist

Description

When declaring a class that inherits from zope.interface.Interface, the suggested refactor is incompatible with the library's behavior.

From zope.interface documentation:

Note that bar doesn’t take a self argument. Interfaces document how an object is used. When calling instance methods, you don’t pass a self argument, so a self argument isn’t included in the interface signature. The self argument in instance methods is really an implementation detail of Python instances.

Code snippet that reproduces issue

from zope.interface import Interface

class IRandomNameService(Interface):
    def foo(name): ...

I expect Sourcery to not alert me about this refactoring when examining the Interface declaration - but for any implementer class, it should continue to recommend adding self, like so:

from zope.interface import implementer

@implementer(IRandomNameService)
class RealRandomNameService:
    def foo(self, name): ...

Debug Information

IDE Version: PyCharm 2023.2 (Professional Edition)

Build #PY-232.8660.197, built on July 26, 2023

Sourcery Version: sourcery.pycharm-plugin (1.7.0)

Operating system and Version: macOS Ventura 13.5 (22G74)

miketheman commented 9 months ago

Is there anything I can do to help correct this? The source for sourcery isn't open, is it?