Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/development_checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Before you commit any changes, check your work against these requirements:
- New dependencies are added to `requirements_all.txt` (if applicable), using `python3 -m script.gen_requirements_all`
- New codeowners are added to `CODEOWNERS` (if applicable), using `python3 -m script.hassfest`
- The `.coveragerc` file is updated to exclude your platform if there are no tests available or your new code uses a third-party library for communication with the device, service, or sensor. `config_flow.py` can't be excluded as it must be fully tested (100% coverage).
- The `.no-strict-typing` file is updated to exclude your code if it doesn't provide a fully type hinted source.
- The code is formatted using Black, as per these [guidelines](https://developers.home-assistant.io/blog/2019/07/31/black.html). This can be done running the command `black --fast homeassistant tests`.
- Documentation is developed for [home-assistant.io](https://home-assistant.io/)
- Visit the [website documentation](/documenting.md) for more information about contributing to [home-assistant.io](https://github.com/home-assistant/home-assistant.io).
9 changes: 7 additions & 2 deletions docs/development_guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ One exception is for logging which uses the percentage formatting. This is to av
_LOGGER.info("Can't connect to the webservice %s at %s", string1, string2)
```

### Typing of functions
### Typing

Either completely type a function or do not type a function at all.
We encourage the use of fully typing your code. This helps with finding/preventing issues and bugs in our codebase,
but also helps fellow contributors making adjustments to your code in the future as well.

By default, Home Assistant will assume everything has type hints and our automated CI process will also check for this.
Python modules can be excluded from this behavior by adding an entry to the `.no-strict-typing` file in the
root of the Home Assistant Core project.
9 changes: 8 additions & 1 deletion docs/development_typing.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ title: "Adding type hints to your code"

Type hints in Python are static annotations of variables and functions, to let humans more easily understand the code. See the standard library [docs](https://docs.python.org/3/library/typing.html) and this PyCascades 2018 [talk](https://youtu.be/zKre4DKAB30).

Type hints are not required for all modules at the moment in Home Assistant, but we aim to have complete coverage of the core modules.
Type hints are not required for all modules at the moment in Home Assistant, but we aim to have a complete as possible coverage.
To improve and encourage this, all code is type checked in our continuous integration process and assumes everything is type checked, unless explicitly excluded from type checking.

Adding type hints to an existing codebase can be a daunting task. To speed this up and help developers doing this, Instagram made the [`monkeytype`](https://pypi.org/project/MonkeyType/) program. It will analyze calls during runtime and try to assign the correct type hints to the code.

Expand All @@ -22,3 +23,9 @@ We've added a script to start a run of our test suite or a test module and tell

**Note:**
Applying a monkeytyped stub to a module that has existing typing annotations might error and not work. This tool is most useful for totally untyped modules.

### Excluding modules from type checking

While we encourage the use of type hints, we currently do not require them for our integrations.
By default, our CI assumes files do have type hints. In case the added module doesn't have this, it can be excluded by adding the module to the `.no-strict-typing` file
that is located at the root of the Home Assistant Core project.