|
| 1 | +# General Advice |
| 2 | + |
| 3 | +### Design |
| 4 | + |
| 5 | +- Make classes lightweight. Prefer module-level functions over class methods. |
| 6 | +- Functions should not be more than 30 lines long. Refactor long functions. |
| 7 | +- Keep the number of function arguments small. Pass common state via |
| 8 | + data transfer objects (DTOs). |
| 9 | +- Use dependency injection to improve configuration and testability. Choose |
| 10 | + sensible defaults for injected dependencies to streamline normal development. |
| 11 | +- Prefer immutability wherever possible. |
| 12 | + |
| 13 | +# Per-Language Advice |
| 14 | + |
| 15 | +## Python |
| 16 | + |
| 17 | +### Design and Idioms |
| 18 | + |
| 19 | +- Target Python 3.10 and use idioms appropriate for that version |
| 20 | + (`match`..`case`, type unions via `|`, etc...). |
| 21 | +- Note the internal `__` subpackage which exposes imports used internally |
| 22 | + throughout the package (`cabc` alias for `collections.abc`, `enum`, `types`, |
| 23 | + `typx` alias for `typing_extensions`, etc...). |
| 24 | +- Do not pollute the module namespace with public imports. Either reference |
| 25 | + common imports from the `__` subpackage or alias module-level imports as |
| 26 | + private. |
| 27 | +- Do not use `__all__` to advertise the public API of a module. Name anything, |
| 28 | + which should not be part of this API, with a private name starting with `_`. |
| 29 | + |
| 30 | +### Documentation and Annotations |
| 31 | + |
| 32 | +- Pad inside of delimiter pairs with spaces. E.g., `( foo )` and not `(foo)`. |
| 33 | + Except in f-strings and `str.format` inputs. |
| 34 | +- Pad binary operators with spaces. E.g., `foo = 42` and not `foo=42`, `1 + 1` |
| 35 | + and not `1+1`, `[ 1 : -n ]` and not `[1:-n]`. |
| 36 | +- Docstrings look like `''' Space-padded headline inside of triple-single |
| 37 | + quotes. '''` and not `"""Double quotes and no spaces are hard to read."""`. |
| 38 | +- Use double-quoted strings for f-strings, `str.format` templates, and log |
| 39 | + messages. Otherwise, use single-quoted strings. |
| 40 | +- Add type hints for arguments, attributes, and return values. |
| 41 | +- Do not write "param spam" documentation which states the obvious. Only |
| 42 | + document non-obvious or complex behaviors on arguments and attributes. |
| 43 | +- Use PEP 593 `Annotated` with PEP 727 `Doc` for argument, attribute, and |
| 44 | + return value documentation, when necessary. |
| 45 | +- Use `TypeAlias` aliases to reuse complex annotations or expose them as part |
| 46 | + of the public API. |
| 47 | + |
| 48 | +### Comments and Lines |
| 49 | + |
| 50 | +- Do not strip comments from existing code unless directed to do so. |
| 51 | +- Do not describe obvious code with comments. Only comment on non-obvious or |
| 52 | + complex behaviors. |
| 53 | +- Leave TODO comments about uncovered edge cases, tests, and other future work. |
| 54 | +- Do not break function bodies with empty lines. |
| 55 | +- One empty line between attribute blocks and methods on classes. |
| 56 | +- Two empty lines between attribute blocks, classes, and functions on modules. |
| 57 | +- Split lines at 79 columns. Use parentheses for continuations and not |
| 58 | + backslashes. |
| 59 | + |
| 60 | +### Lints and Tests |
| 61 | + |
| 62 | +- Check your work by linting, ensuring that the package imports, running tests, |
| 63 | + and generating documentation. |
| 64 | +- Ignore any warnings, unless instructed otherwise. Focus only on errors and |
| 65 | + failures. |
| 66 | +- To run linters, use `hatch --env develop run linters`. |
| 67 | +- To run testers, use `hatch --env develop run testers`. |
| 68 | +- To generate documentation, use `hatch --env develop run docsgen`. |
| 69 | +- Do not write tests unless explicitly instructed to do so. |
| 70 | + |
| 71 | +# Commits |
| 72 | + |
| 73 | +- Use `git status` to ensure that all relevant changes are in the changeset to |
| 74 | + be committed. |
| 75 | +- Look at the previous five commit messages for guidance on message style. |
| 76 | +- Use present tense, imperative mood verbs to describe changes. E.g. "Fix" and |
| 77 | + *not* "Fixed". |
| 78 | +- The commit message should include a `Co-Authored-By:` field as its final |
| 79 | + line. The name of the author should be your model name. The email address |
| 80 | + should either be one which you have been designated to use or else a |
| 81 | + commonly-known no-reply address. |
| 82 | + |
| 83 | +## Interactive Collaboration on User Terminal |
| 84 | + |
| 85 | +- Do not commit until you have user approval to do so. |
| 86 | +- Add the `--no-gpg-sign` option to the `git commit` command to suppress GPG |
| 87 | + passphrase challenges. (These challenges conflict with the alternate console |
| 88 | + screen, managed by some CLI agents, resulting in an unusable terminal.) |
0 commit comments