Skip to content

Code Style

Matheus Vilano edited this page Jun 14, 2024 · 3 revisions

Naming Convention

All code must follow the standard Python naming convention:

  • Package: somepackagename
  • Module: some_module_name.py
  • Constants: SOME_CONSTANT_NAME *
  • Variables: some_variable_name
  • Functions: some_function_name
  • Classes: SomeClassName
  • Enums: ESomeEnumName.SOME_ENUM_VALUE

* As constants are not supported in Python, the convention just indicates intent.

Code Style

Comments

Keep comments to a minimum. Prefer descriptive names/identifiers over comments. Only explain what needs explanation (e.g. a very complex one-liner).

Spacing

All code must follow the standard Python rules for spacing:

  • On a global scale, keep definitions 2 lines away from each other.
  • On a local scale, keep definitions 1 line away from each other.
  • When commenting in-line, keep the # character 2 chars away from code.

Type Hints

Mandatory when:

  • Using factory functions (e.g. pywwise.new, which returns an instance of Ak).
  • Defining a function (e.g. def load_bank(bank: Name | ShortID | GUID) -> bool: pass).

Recommended when:

  • Assigning a variable's value/reference to another variable where the type is not obvious (e.g. current: int = first).

Important notes:

  • Prefer the | notation over Union.

Documentation

All non-local declarations/definitions must be documented using Python docstrings, even if there is not much to say (e.g. class Vector3: \ """A 3-dimensional vector (x, y, z)."""). The only allowed docstring format is reStructuredText.

Sidebar test

Clone this wiki locally