[red-knot] Add __init__ arguments check when doing try_call on a class literal (#16512)

## Summary

* Addresses #16511 for simple cases where only `__init__` method is
bound on class or doesn't exist at all.
* fixes a bug with argument counting in bound method diagnostics

Caveats:
* No handling of `__new__` or modified `__call__` on metaclass.
* This leads to a couple of false positive errors in tests

## Test Plan

- A couple new cases in mdtests
- cargo nextest run -p red_knot_python_semantic --no-fail-fast

---------

Co-authored-by: Carl Meyer <carl@astral.sh>
Co-authored-by: David Peter <sharkdp@users.noreply.github.com>
This commit is contained in:
Mike Perlov
2025-04-08 23:26:20 +02:00
committed by GitHub
parent ed14dbb1a2
commit fab7d820bd
11 changed files with 853 additions and 121 deletions

View File

@@ -8,7 +8,11 @@ Currently, red-knot doesn't support `typing.NewType` in type annotations.
from typing_extensions import NewType
from types import GenericAlias
X = GenericAlias(type, ())
A = NewType("A", int)
# TODO: typeshed for `typing.GenericAlias` uses `type` for the first argument. `NewType` should be special-cased
# to be compatible with `type`
# error: [invalid-argument-type] "Object of type `NewType` cannot be assigned to parameter 2 (`origin`) of function `__new__`; expected type `type`"
B = GenericAlias(A, ())
def _(