micropython-stubber icon indicating copy to clipboard operation
micropython-stubber copied to clipboard

Verify correct effects of mypy switch Any --> Incomplete

Open Josverl opened this issue 3 years ago • 1 comments

Describe

A clear and concise description of what the bug is.

a change in mypy is causing a lot of stubs to be annotated as class Incomplete rather than Any

  • first seen in : stubber "version": "1.7.2",
  • possibly introduced by : build(deps): bump mypy from 0.931 to 0.971 Commit: 78dd426affe7b69535b69f0ab3466d806dcf75e9

This is mentioned at MyPy in :

  • ref : https://github.com/python/typeshed/pull/8458

Before webrepl.pyi

from typing import Any

listen_s: Any
client_s: Any

def setup_conn(port, accept_handler): ...
def accept_conn(listen_sock) -> None: ...
def stop() -> None: ...
def start(port: int = ..., password: Any | None = ...) -> None: ...
def start_foreground(port: int = ...) -> None: ...

After webrepl.pyi

from _typeshed import Incomplete

listen_s: Incomplete
client_s: Incomplete

def setup_conn(port, accept_handler): ...
def accept_conn(listen_sock) -> None: ...
def stop() -> None: ...
def start(port: int = ..., password: Incomplete | None = ...) -> None: ...
def start_foreground(port: int = ...) -> None: ...

To Reproduce Expected behavior A clear and concise description of what you expected to happen.

  • [ ] test if the stubs work without further changes , or identify changes if needed
  • [ ] ?? update firmware stubber to use this as well ??

Josverl avatar Aug 12 '22 16:08 Josverl

Seems to work fine as long as typeshed is installed Incomplete is an alias for Any, but need to test on older python versions as well

or add _typeshed as a depedency of the stub packages

Note: _typeshed is already included as a fallback pakage for Pylance & Pyright

# Utility types for typeshed

This package and its submodules contains various common types used by
typeshed. It can also be used by packages outside typeshed, but beware
the API stability guarantees below.

## Usage

The `_typeshed` package and its types do not exist at runtime, but can be
used freely in stubs (`.pyi`) files. To import the types from this package in
implementation (`.py`) files, use the following construct:

```python
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from _typeshed import ...
```

Types can then be used in annotations by either quoting them or
using:

```python
from __future__ import annotations
```

Josverl avatar Aug 12 '22 19:08 Josverl