typest
An experimental framework to test your library against type checkers, allowing
to formulate type expectations and expected typechecker errors. Its purpose is
the same as the one of
pytest-mypy-plugins. While
pytest-mypy-plugins requires .yaml files for specifying the tests, typest
test cases are python files, expectations are formulated in comments:
from mylibrary import some_function
result = some_function()
reveal_type(result) # expect-type: int
Besides expressing type expectations, you can also specify to expect an error from the typechecker:
string: str = "not a number"
number: int = string # expect-error
You can also specify to expect a mismatch error, i.e. an error where an assigned type is mismatching the actual type:
string: str = "not a number"
number: int = string # expect-mismatch: int <> str
Suppported Typecheckers
mypypyright
Installation
typest is available at pypi. You can install it through pip:
pip install typest
Use
python -m typest [PATH] [TYPECHECKERS]
If PATH is a directory, all python files under that directory (including subdirectories) are going to be checked. If PATH points to a file, it has to be a python file.
TYPECHECKERS is an optional argument, a comma separated list of names of
typecheckers you want to run your tests against. Currently, mypy and pyright
are suppported.
Development
You can add more typecheckers by subclassing
typest.typecheckers.base.TypeChecker and importing your new class in
typest/typecheckers/__init__.py.
Metadata
Release files for typest 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| typest-0.3.2.tar.gz | 7.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| typest-0.3.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.4 kB
Release files / typest-0.3.2.tar.gz
| Download URL | typest-0.3.2.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4425170fdbd83f3fc0ab8cfccb0bf5fdf4a87240758d4d7c66dc5e0a14e02071
|
|
BLAKE2b-256 checksum How to use checksums |
6b2301619008786b90fd985fccdde42f44354bd0039c24cd47dc9300db30d554
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.1 CPython/3.10.6 Linux/5.15.0-57-generic
|
Release files / typest-0.3.2-py3-none-any.whl
| Download URL | typest-0.3.2-py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6bf52b759c5a88c097244a3ecf57402ca65c6017ea1e775dfdfdf21bed0ef6db
|
|
BLAKE2b-256 checksum How to use checksums |
c119b369d3956859962b33c1327db67a506a5d140644b1603407c06d81fc2cee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.1 CPython/3.10.6 Linux/5.15.0-57-generic
|