Writing Python libraries

If working on a library that has some strict lower Python version, e.g. lower than 3.10, then it is a good idea to require pyright locally, to have a local poetry.toml file with the following

[virtualenvs]
in-project = true

And to have pyright use this particular virtual environment. In pyproject.toml

[tools.pyright]
venvPath = "."
venv = ".venv"

What this will do is require that the pyright version your editor uses be limited to the language features of the required Python version. For example, it will complain about importing TypeAlias from typing. Further more we want to only include type stubs that are local to the project and its dependencies, so we need to tell pyright via the venvPath and venv configurations that it should only look in the local virtual environment.

I learned this all by first putting together a stubs library for mysql-connector-python that I wanted to support down to 3.7, but forgot to replace my prior usage of TypeAlias. When I included this stubs library in 3.8 project, pyright was okay with everything except for those calls that used a TypeAliased parameter, and I had a hard time figuring out why for quite a while. Once those usages were replace with the full types pyright was happy.