aboutcode-org / aboutcode-org/scancode-toolkit

Provide type hints for PEP 561 compliance

オープン
#3,487 コメント 0 件 リアクション 2 件 担当者 0 名 GitHub で見る
new feature
主要言語
Python
スター
2.6k
フォーク
791
平均マージ
1日 12時間
マージ済み PR(30日)
5

説明

## Short Description

To use the ScanCode toolkit as a library, it would be great if type hints for corresponding checkers like *mypy* would be provided.

## Possible Labels

- new feature
- enhancement

## Select Category

- [X] Enhancement
- [ ] Add License/Copyright
- [ ] Scan Feature
- [ ] Packaging
- [ ] Documentation
- [ ] Expand Support
- [ ] Other

## **Describe the Update**

ScanCode toolkit and the corresponding dependencies like *commoncode* should receive type hints and target PEP 561 with this.

## **How This Feature will help you/your organization**

As already mentioned in #3431, I am primarily using ScanCode toolkit as a library for license scanning. Properly typing my code requires suitable typing information for all dependencies as well and avoid possible type issues.

At the moment, running corresponding tools like *mypy* requires me to ignore warnings about possibly untyped code:

```bash
stefan@localhost ~/projects/license_tools $ mypy license_tools
license_tools/scancode_tools.py:24: error: Skipping analyzing "scancode_config": module is installed, but missing library stubs or py.typed marker [import]
license_tools/scancode_tools.py:24: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
license_tools/scancode_tools.py:25: error: Skipping analyzing "commoncode": module is installed, but missing library stubs or py.typed marker [import]
license_tools/scancode_tools.py:27: error: Skipping analyzing "scancode": module is installed, but missing library stubs or py.typed marker [import]
```

## **Possible Solution/Implementation Details**

The stdlib *typing* module provides support for typing: https://docs.python.org/3/library/typing.html Starting at Python 3.8, some aspects might be simplified due to support for the new `from __future__ import annotations` functionality.

*mypy* provides the *stubgen* tool for generating `*.pyi` stubs with harmless dummy data which pass all type checks: https://mypy.readthedocs.io/en/stable/stubgen.html Nevertheless, I would probably recommend to work on the actual code directly as the `*.pyi` files are just some sort of workaround.

Once fully typed, a `py.typed` file should be shipped with the corresponding packages.

## **Can you help with this Feature**

The ScanCode/nexB ecosystem is quite large, thus probably requiring work across multiple repositories and prioritization. I would be up to support with this process.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。