microsoft / pyright

Static Type Checker for Python
Other
13.13k stars 1.4k forks source link

Imprecise error message for `reportInconsistentConstructor` #8500

Closed JelleZijlstra closed 1 month ago

JelleZijlstra commented 1 month ago

Given this program:

from typing import Self

class X:
    def __new__(cls, *args: object, **kwargs: object) -> Self: ...
    def __init__(self, *args: object, a: int) -> None: ...

Pyright correctly reports reportInconsistentConstructor. However, the error message is not great:

Mismatch between signature of __new__ and __init__ in class "X"
  Signature of __init__ is "(..., a: int)"
  Signature of __new__ is "..."  (reportInconsistentConstructor)

I would interpret Signature of __new__ is "..." to mean that it's a signature like Callable[..., T], but that's not what's happening here.

This came up in python/typeshed#12346.

erictraut commented 1 month ago

This is addressed in pyright 1.1.373.