PyCharm plugin: zope.interface

Answered

I'm working on a plugin for PyCharm to make using zope.interface easier, but have hit a bit of a snag.  There are two main changes needed.  The first is to find all subclasses of zope.interface.Interface, disable auto-entering the first parameter (self), and disabling the 'Methods having troubles with first parameter' inspection on the subclasses.  

Second is to find all classes which are decorated by a call to zope.interface.implements and ensure they implement the referenced interface.  

I'm fairly certain I can find the subclasses already, but I'm not sure how to disable the inspection specifically for them.  I have no idea how to find calls to zope.interface.implements, especially considering the variety of ways it could be imported.  Once I have the interface class, writing the inspection should be fairly simple.  Anyway, I'd appreciate any pointers on where to start, or if there is pycharm-specific plugin documentation available, a link to that.

1 comment
Comment actions Permalink

Code analysis in PyCharm works a bit differently. Instead of finding all the code elements of a particular kind you usually provide your custom analysis for a single code element. It's the job of our inspections engine to run your analysis on all the elements in the current file.

One of the possibilities is to modify how PyCharm looks at the parameters of a function. You could start by looking at the implementations of the `PyTypeProvider` inferface (especially at `PyTypeProvider.getCallableType()`). You could try to provide your modified `PyCallableType` for a `PyFunction` (see `PyCallableTypeImpl`, `PyCallableParameter`).

Another way could be just to disable certain inspections for particular functions. We have `PyInspectionExtension` for this, but it's fairly ad hoc and gives your the ability to disable only certain things.

0

Please sign in to leave a comment.