Calculate the Type Coverage for top Python packages.
Take the top pypi packages pulled from this project https://github.com/hugovk/top-pypi-packages
View report here: https://html-preview.github.io/?url=https://github.com/lolpack/type_coverage_py/blob/main/index.html
This section outlines how the script analyzes Python packages, checks for typeshed availability, and calculates type coverage. The process involves three key steps: package extraction, typeshed check, and type coverage calculation.
.py
) and type stub files (.pyi
) from the package for analysis.typeshed
repository, which contains type stubs for standard library modules and popular third-party packages.HasTypeShed: Yes
; otherwise, it is marked as HasTypeShed: No
..pyi
file exists, prefer it over typeshed. Parameter Coverage:
.pyi
files: If a function is defined in a .pyi
file, it takes precedence over any corresponding function in a .py
file. The parameter counts from .pyi
files will overwrite those from .py
files for the same function.Return Type Coverage:
.pyi
files: Similar to parameter coverage, if a function is defined in a .pyi
file, the return type annotations from the .pyi
file will overwrite those from any corresponding .py
file.Skipped Files:
Overall Coverage:
This methodology ensures an accurate and detailed analysis of type coverage for popular Python packages, taking into account the presence of type stub files (.pyi
) which are prioritized over implementation files (.py
) for the same functions.
Clone the typeshed repo into the root of the project
git clone git@github.com:python/typeshed.git
Call the main function with the top N packages to analyze, the max is 8,000.
python main.py 100
Alternatively call with a single package
python main.py --package-name flask
Analyze the top N packages and generate both JSON and HTML reports:
python main.py 100 --write-json --write-html