2024-09-24 08:56:37 +00:00
|
|
|
|
import { _ as _export_sfc, c as createElementBlock, o as openBlock, a8 as createStaticVNode } from "./chunks/framework.B9AX-CPi.js";
|
2024-11-12 02:22:17 +00:00
|
|
|
|
const __pageData = JSON.parse('{"title":"Coding Conventions (Python)","description":"","frontmatter":{},"headers":[],"relativePath":"coding_conventions_python.md","filePath":"coding_conventions_python.md","lastUpdated":null}');
|
2024-05-30 02:02:10 +00:00
|
|
|
|
const _sfc_main = { name: "coding_conventions_python.md" };
|
|
|
|
|
const _hoisted_1 = /* @__PURE__ */ createStaticVNode('<h1 id="coding-conventions-python" tabindex="-1">Coding Conventions (Python) <a class="header-anchor" href="#coding-conventions-python" aria-label="Permalink to "Coding Conventions (Python)""></a></h1><p>Most of our style follows PEP8 with some local modifications to make things less nit-picky.</p><ul><li>We target Python 3.7 for compatibility with all supported platforms.</li><li>We indent using four (4) spaces (soft tabs)</li><li>We encourage liberal use of comments <ul><li>Think of them as a story describing the feature</li><li>Use them liberally to explain why particular decisions were made.</li><li>Do not write obvious comments</li><li>If you're not sure if a comment is obvious, go ahead and include it.</li></ul></li><li>We require useful docstrings for all functions.</li><li>In general we don't wrap lines, they can be as long as needed. If you do choose to wrap lines please do not wrap any wider than 76 columns.</li><li>Some of our practices conflict with the wider python community to make our codebase more approachable to non-pythonistas.</li></ul><h1 id="yapf" tabindex="-1">YAPF <a class="header-anchor" href="#yapf" aria-label="Permalink to "YAPF""></a></h1><p>You can use <a href="https://github.com/google/yapf" target="_blank" rel="noreferrer">yapf</a> to style your code. We provide a config in <a href="https://github.com/qmk/qmk_firmware/blob/master/setup.cfg" target="_blank" rel="noreferrer">setup.cfg</a>.</p><h1 id="imports" tabindex="-1">Imports <a class="header-anchor" href="#imports" aria-label="Permalink to "Imports""></a></h1><p>We don't have a hard and fast rule for when to use <code>import ...</code> vs <code>from ... import ...</code>. Understandability and maintainability is our ultimate goal.</p><p>Generally we prefer to import specific function and class names from a module to keep code shorter and easier to understand. Sometimes this results in a name that is ambiguous, and in such cases we prefer to import the module instead. You should avoid using the "as" keyword when importing, unless you are importing a compatibility module.</p><p>Imports should be one line per module. We group import statements together using the standard python rules- system, 3rd party, local.</p><p>Do not use <code>from foo import *</code>. Supply a list of objects you want to import instead, or import the whole module.</p><h2 id="import-examples" tabindex="-1">Import Examples <a class="header-anchor" href="#import-examples" aria-label="Permalink to "Import Examples""></a></h2><p>Good:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span>from qmk import effects</span></span>\n<span class="line"><span></span></span>\n<span class="line"><span>effects.echo()</span></span></code></pre></div><p>Bad:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span>from qmk.effects import echo</span></span>\n<span class="line"><span></span></span>\n<span class="line"><span>echo() # It's unclear where echo comes from</span></span></code></pre></div><p>Good:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span>from qmk.keymap import compile_firmware</span></span>\n<span class="line"><span></span></span>\n<span class="line"><span>compile_firmware()</span></span></code></pre></div><p>OK, but the above is better:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span>import qmk.keymap<
|
|
|
|
|
const _hoisted_109 = [
|
|
|
|
|
_hoisted_1
|
|
|
|
|
];
|
|
|
|
|
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
|
|
return openBlock(), createElementBlock("div", null, _hoisted_109);
|
|
|
|
|
}
|
|
|
|
|
const coding_conventions_python = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
|
|
|
|
|
export {
|
|
|
|
|
__pageData,
|
|
|
|
|
coding_conventions_python as default
|
|
|
|
|
};
|