aboutcode-org / aboutcode-org/scancode-toolkit

Provide type hints for PEP 561 compliance

Đang mở
#3,487 0 bình luận 2 reaction 0 người được giao Xem trên GitHub
new feature
Ngôn ngữ chính
Python
Star
2.6k
Fork
791
Merge trung bình
1 ngày 12 giờ
Pull request đã merge (30 ngày)
5

Mô tả

## 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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.