# python


03/18/2024, 10:42 PM
Can anyone recommend best practices around type checking, declaration and enforcement of Pulumi/Python code?
I know we can introduce pep-0484 type hints and a static analysis type checking tool like mypy... is this the best practice? Are there any pitfalls or other concerns to be aware of?
I've integrated poetry with taskpi to bootstrap flake8 for linting and mypy for static type checking...


03/21/2024, 4:58 PM
After This is what I've been using in my setup. • Pyright – Run under the Pylance language server in VScode • Ruff – with linting and auto formatting on save – btw. it's orders of magnitude faster than Flake8, Pylint etc. • pre-commit hooks for those as well to ensure type checking and formatting • Pydantic – For managing and validating basically all provider/stack/resource configurations – I feel like this was the biggest game changer for us in terms of enforcement and validation If you turn on package type indexing in your IDE for autocompletion and validation you might run into problems with some Pulumi packages as they contain so many symbols. I had to limit indexing to 2 level down (basically leaving out the additional versioned API sub-modules) otherwise VSCode would blow up. Just be prepared for a pretty steep learning curve on the Pulumi Output and the internal asyncio event loop – I learned it the hard way I guess by reading through the source code after implementing Pydantic validation/serialization in my Pulumi code. Documentation is really lacking there.


03/22/2024, 1:54 AM
Thank you @adventurous-butcher-54166 this is great info 🙏