-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Dev: Coding Style
Adapted from https://docs.djangoproject.com/en/1.7/internals/contributing/writing-code/coding-style/
Note: This is a work in progress!
Please follow these coding standards when writing code for inclusion in Spyder.
Unless otherwise specified, follow PEP 8.
Use flake8 to check for problems in this area. Remember that PEP 8 is only a guide, so respect the style of the surrounding code as a primary goal.
- Always use four (4) spaces for indentation.
Spyder aims to be compatible with PySide and PyQt, so make sure code runs with both bindings.
Qt by default has its own conventions for the definitions of methods and classes, and sometimes this clashes with was is suggested by PEP 8.
These are some suggestions to take into account when using the Qt bindings in Python:
-
Qt defines methods in camelCase, and when Spyder overloads these methods, we cannot avoid camelCase. However, When new methods are defined in Spyder, these methods should follow the PEP8 convention:
class SpyderWidget(QWidget): """Example widget.""" def __init__(self, parent): QWidget.__init__(self, parent) def mousePressEvent(self, event): """Overloaded Qt method.""" # Do something with the event... def run_new_method(self): """Run some new method.""" # Do something interesting
- When working with signals, use the new style:
- For naming new custom signals, use the
sig_
prefixfrom spyderlib.qt.QtCore import Signal class SpyderWidget(SpyderPluginWidget): """Multi-file Editor widget""" # Signals sig_run_in_current_ipyclient = Signal(str, str, str, bool, bool)
TODO:
from spyderlib.baseconfig import _
Connect with Spyder through our social media channels and stay up to date with current developments!