Code conventions

Formatting

Code is formatted with ruff, settings are in pyproject.toml: indents of 4 spaces, single quotes, lines up to 150 characters.

Imports

Import modules, not names, and use qualified names:

import gws.lib.osx

gws.lib.osx.run(cmd)

Exceptions are typing names (from typing import Optional, cast) and relative imports within a package (from . import provider).

Group imports in this order, separated by blank lines:

  1. typing
  2. standard library
  3. third-party libraries
  4. import gws, then other gws modules
  5. relative imports

Naming

KindStyleExample
classesCapWordsFeatureProps
fields of data classes, object attributescamelCasetableName, self.serverMgr
functions, methods, local variablessnake_casecreate_child, layer_uid
modulessnake_caseauth_provider
constantsUPPER_CASEMAX_BOX_SIZE
commandscamelCasemapGetFeatures
module-private namesleading underscore_read_file

Configuration keys, request parameters and props are camelCase, because they are shared with the client and the configuration files.

Modules

A module that implements an extension type defines Config, Props and Object under these names. Interfaces from gws are implemented by a class with the same name in the implementing package, for example gws.base.feature.Feature implements gws.Feature.

Types

Annotate the fields of data classes, they define the specs. Annotate object attributes at the class level and function signatures where the types are not obvious. Use Optional[T] for optional fields of data classes, the spec generator uses it to determine defaults.

Docstrings

Docstrings follow the Google style. Start every module with a docstring. Field docstrings follow the field:

class Config(gws.Config):
    """Search provider."""

    url: gws.Url
    """Service url."""