Skip to content

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

Open
@miketheman

Description

@miketheman

Checklist

  • I have searched the Sourcery documentation for the issue, and found nothing
  • I have checked there are no open bugs referencing the same bug or problem

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)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions