Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[red-knot] Check __init__ arguments when doing try_call on a class literal #16511

Open
mishamsk opened this issue Mar 5, 2025 · 0 comments
Open
Assignees
Labels
red-knot Multi-file analysis & type inference

Comments

@mishamsk
Copy link
Contributor

mishamsk commented Mar 5, 2025

Description

Currently red knot assumes all calls to class literals are valid and create instances. E.g. this test yields no diagnostic currently

from typing import Literal

class Number:
    def __init__(self, value: int):
        self.value = 1

    def __pos__(self) -> int:
        return +self.value

    def __neg__(self) -> int:
        return -self.value

    def __invert__(self) -> Literal[True]:
        return True

a = Number()

We should check __init__ signature just like any other call and emit diagnostics.

This is step 1 in a series of feature to support the instance creation process in full. The related logic of handling type[C] is tracked in #15948

mishamsk added a commit to mishamsk/ruff that referenced this issue Mar 5, 2025
@mishamsk mishamsk changed the title [red-knot] Check __init__ arguments on class literals call [red-knot] Check __init__ arguments when doing try_call on a class literal Mar 5, 2025
@mishamsk mishamsk changed the title [red-knot] Check __init__ arguments when doing try_call on a class literal [red-knot] Check __init__ arguments when doing try_call on a class literal Mar 5, 2025
@MichaReiser MichaReiser added the red-knot Multi-file analysis & type inference label Mar 5, 2025
@MichaReiser MichaReiser added this to the Red Knot Q1 2025 milestone Mar 5, 2025
mishamsk added a commit to mishamsk/ruff that referenced this issue Mar 7, 2025
mishamsk added a commit to mishamsk/ruff that referenced this issue Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

No branches or pull requests

2 participants