microsoft / microsoft/pyright

New-types seem to have an under-specified callable signature of `(...) -> Any` on 1.1.402

Open
#10,668 0 comments 0 reactions 0 assignees View on GitHub
bug regression
Dominant language
Python
Stars
15.6k
Forks
1.8k
Avg merge
12h 13m
Merged PRs (30d)
52

Description

**Describe the bug**

Types created with `NewType` seem to have a callable signature of `(...) -> Any` now instead of `(old_type) -> new_type`.

**Code or Screenshots**

```python
from __future__ import annotations

from collections.abc import Callable
from typing import NewType, Protocol

NewInt = NewType("NewInt", int)

class FP(Protocol):
def __call__(self, /) -> None: ...

fp: FP = NewInt # Expected to be reported as incompatible, but NOT.

def call[**P, T](f: Callable[P, T], *args: P.args, **kwargs: P.kwargs) -> T: ...
reveal_type(call(NewInt, 0)) # Expected to have a result type of `NewInt`, but got `Any` instead.
call(NewInt) # Expected to be reported as invalid call, but NOT.
```

**VS Code extension or command-line**

This behavior is new since 1.1.402.

Contributor guide

Open the contributing guide

Research direction

Run the provided Python reproducer against Pyright 1.1.402 and compare its diagnostics and revealed type with the expected results. Trace the NewType callable-signature handling; done means incompatible assignments and missing arguments are reported, and the generic call reveals NewInt rather than Any.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.