From 5174f382b9f097042d6bc2da3cbc85f481a943b3 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Fri, 29 Sep 2023 00:09:38 +1000 Subject: [PATCH] Update LOCAL_DEVELOPMENT.md add LSP and type checking notes --- docs/contributing/LOCAL_DEVELOPMENT.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/contributing/LOCAL_DEVELOPMENT.md b/docs/contributing/LOCAL_DEVELOPMENT.md index f93ec56e96..01b65923f4 100644 --- a/docs/contributing/LOCAL_DEVELOPMENT.md +++ b/docs/contributing/LOCAL_DEVELOPMENT.md @@ -167,6 +167,23 @@ and so you'll have access to the same python environment as the InvokeAI app. This is _super_ handy. +#### Enabling Type-Checking with Pylance + +We use python's typing system in InvokeAI. PR reviews will include checking that types are present and correct. We don't enforce types with `mypy` at this time, but that is on the horizon. + +Using a code analysis tool to automatically type check your code (and types) is very important when writing with types. These tools provide immediate feedback in your editor when types are incorrect, and following their suggestions lead to fewer runtime bugs. + +Pylance, installed at the beginning of this guide, is the de-facto python LSP (language server protocol). It provides type checking in the editor (among many other features). Once installed, you do need to enable type checking manually: + +- Open a python file +- Look along the status bar in VSCode for `{ } Python` +- Click the `{ }` +- Turn type checking on - basic is fine + +You'll now see red squiggly lines where type issues are detected. Hover your cursor over the indicated symbols to see what's wrong. + +In 99% of cases when the type checker says there is a problem, there really is a problem, and you should take some time to understand and resolve what it is pointing out. + #### Debugging configs with `launch.json` Debugging configs are managed in a `launch.json` file. Like most VSCode configs,