aboutcode-org / aboutcode-org/scancode-toolkit

Provide type hints for PEP 561 compliance

Abierto
#3,487 0 comentarios 2 reacciones 0 asignados Ver en GitHub
new feature
Lenguaje dominante
Python
Estrellas
2.6k
Forks
791
Merge medio
1 d 12 h
PR fusionados (30 d)
5

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.