Please read these guidelines before contributing to the project.
Attribute Type | Python | PowerShell |
---|---|---|
Qt slots and signals | camelCase | |
Classes | PascalCase | PascalCase |
MetaClasses | PascalCase | |
Type Aliases | PascalCase | |
Functions | snake_case | Verb-Noun |
Methods | snake_case | PascalCase |
Modules | snake_case | PascalCase |
Packages | snake_case | |
Parameters | snake_case | PascalCase |
Properties | snake_case | PascalCase |
Variables | snake_case | PascalCase |
Constants | SCREAMING_SNAKE_CASE | PascalCase |
Generics | PascalT_lower_co |
Convention Type | Examples |
---|---|
lowercase | foo, foobar, foobarbiz |
UPPERCASE | FOO, FOOBAR, FOOBARBIZ |
camelCase | foo, fooBar, fooBarBiz |
PascalCase | Foo, FooBar, FooBarBiz |
snake_case | foo, foo_bar, foo_bar_biz |
SCREAMING_SNAKE_CASE | FOO, FOO_BAR, FOO_BAR_BIZ |
PascalT_lower_co | FT, BarT_co, FT_covar |
Verb-Noun | New-Shortcut, Get-Value |
Copyright headers, docstrings, and an __all__
attribute are mandatory.
Order of module elements:
-
Shebang line, if included.
-
Copyright header
-
Module's docstring
-
Any
from __future__
imports -
Dunder variables (ex:
__all__
) -
Imports
-
Constants
-
Functions
-
Classes
-
if __name__ == '__main__':
entrypoint
Full Example:
#!/usr/bin/env python
############################
# License and copyright text
############################
"""This is a module's docstring."""
from __future__ import annotations
__all__ = (
'CONSTANT',
'foo',
'Foo',
)
from foo import Bar
CONSTANT = 1
def foo():
"""This is a function's docstring."""
class Foo(Bar):
"""This is a class's docstring."""
if __name__ == '__main__':
foo()
__all__
should be a tuple containing the module's public attributes meant for import, ordered alphabetically.
__future__
imports are not to be grouped with other imports, and should be right below the module docstring.
Imports should be formatted as follows:
-
Modules from the stdlib
- module imports
from
imports
-
External modules (included in the project's requirements)
- module imports
from
imports
-
Local modules
- Parent packages should be placed above their child packages
- Module imports should be placed above their package's
from
imports
from
imports from a parent packagefrom
imports from the current package
Other rules:
-
The main three categories should be separated by line breaks.
-
All imports should be on a single line, and should be sorted alphabetically.
-
All local imports should be relative imports. Ex:
from .module import Class
as opposed tofrom module import Class
. -
When importing multiple attributes from a module, each line should contain one import. Ex:
from module import attribute
from module import other_attribute
- Only
import *
modules which have an__all__
attribute defined.
Full Example:
import os
from pathlib import Path
import external_module
from other_external_module import external_function
from ...parents_parent_package_module import a1
from .. import parent_package_module
from ..other_parent_package_module import b1
from ..other_parent_package_module import b2
from . import current_package_module
from .another_current_package_module import c1
from .other_current_package_module import *