Skip to content

Dev: Coding Style

Gonzalo Peña-Castellanos edited this page Apr 15, 2015 · 21 revisions

Adapted from https://docs.djangoproject.com/en/1.7/internals/contributing/writing-code/coding-style/

Note: This is a work in progress!

Coding style

Please follow these coding standards when writing code for inclusion in Spyder.

Python style

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.

PyQt / PySide Style

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

Signals

  • When working with signals, use the new style:
  • For naming new custom signals, use the sig_ prefix
    from spyderlib.qt.QtCore import Signal
    
    class SpyderWidget(SpyderPluginWidget):
        """Multi-file Editor widget"""    
    
        # Signals
        sig_run_in_current_ipyclient = Signal(str, str, str, bool, bool)

Internationalization / Localization

TODO:

from spyderlib.baseconfig import _
Clone this wiki locally