Package: pyright
Pyright for PythonThis project is not affiliated with Microsoft in any way, shape, or formPyright for Python is a Python command-line wrapper overpyright, a static type checker for Python.InstallationUse the package managerpipto install pyright.pipinstallpyrightUsagePyright can be invoked using two different methodspyright--helporpython3-mpyright--helpPyright for Python should work exactly the same as pyright does, see thepyright documentationfor details on how to make use of pyright.Pre-commitYou can also setup pyright to run automatically before each commit by setting uppre-commitand registering pyright in your.pre-commit-config.yamlfilerepos:-repo:https://github.com/RobertCraigie/pyright-pythonrev:v1.1.352hooks:-id:pyrightPre-commit will install pyright-python in its own virtual environment which can cause pyright to not be able to detect your installed dependencies.To fix this you can eithertell pre-committo also install those dependencies or explicitly tell pyright which virtual environment to use by updating yourpyright configuration file:[tool.pyright]# ...venvPath="."venv=".venv"MotivationPyrightis written in TypeScript, requiring node to be installed, and is normally installed with npm. This could be an entry barrier for some Python developers as they may not have node or npm installed on their machine; I wanted to make pyright as easy to install as any normal Python package.How Pyright for Python WorksThis project works by first checking if node is in thePATH. If it is not, then we download node at runtime usingnodeenv, then install the pyright npm package usingnpmand finally, run the downloaded JS withnode.Automatically keeping pyright up to dateBy default Pyright for Python is set to target a specific pyright version and new releases will be automatically created whenever a new pyright version is released. It is highly recommended to use an automatic dependency update tool such asdependabot.If you would rather not have to update your installation every time a new pyright release is created then you can automatically use the latest available pyright version by setting the environment variablePYRIGHT_PYTHON_FORCE_VERSIONtolatest.ConfigurationYou can configure Pyright for Python using environment variables.DebuggingSetPYRIGHT_PYTHON_DEBUGto any value.Modify Pyright VersionSetPYRIGHT_PYTHON_FORCE_VERSIONto the desired version, e.g.1.1.156,latestKeeping Pyright and Pylance in syncSetPYRIGHT_PYTHON_PYLANCE_VERSIONto your Pylance version, e.g.2023.11.11,latest-release,latest-prerelease. The corresponding Pyright version will be used. SeePylance's changelogfor details on recent releases. Note thatPYRIGHT_PYTHON_FORCE_VERSIONtakes precedence overPYRIGHT_PYTHON_PYLANCE_VERSION, so you'll want to set one or the other, not both.Show NPM logsBy default, Pyright for Python disables npm error messages, if you want to display the npm error messages then setPYRIGHT_PYTHON_VERBOSEto any truthy value.Modify NPM Package LocationPyright for Python will resolve the root cache directory by checking the following environment variables, in order:PYRIGHT_PYTHON_CACHE_DIRXDG_CACHE_HOMEIf neither of them are set it defaults to~/.cacheForce Node EnvSetPYRIGHT_PYTHON_GLOBAL_NODEto any non-truthy value, i.e. anything apart from 1, t, on, or true.
e.g.offYou can optionally choose the version of node used by settingPYRIGHT_PYTHON_NODE_VERSIONto the desired versionModify Node Env LocationSetPYRIGHT_PYTHON_ENV_DIRto a validnodeenvdirectory. e.g.~/.cache/nodeenvIgnore WarningsSetPYRIGHT_PYTHON_IGNORE_WARNINGSto a truthy value, e.g. 1, t, on, or true.Pyright for Python will print warnings for the following case(s)There is a new Pyright version available.ContributingAll pull requests are welcome.LicenseMIT