Skip to content

Better error location for incompatible override due to argument incompatibility #8298

Closed

Description

@JukkaL

An incompatible override gets reported on the first line of a method header, even though it would be better to point it at the line with an argument that is incompatible, when possible. Example:

class A:
    def f(self, x: int, y: str, z: float) -> None: pass

class B(A):
    def f(  # Argument 3 incompatible with supertype "A" <-- reported here
            self,
            x: int,
            y: str,
            z: bool,  # <-- would be better to report it here
    ) -> None:
        pass

This would improve usability, especially for methods with many arguments on many lines. This would also make it cleaner to ignore these errors, as the location of the # type: ignore comment would document which argument is incompatible (if there is one argument per line, which is a common convention).

Activity

  1. dhalenok commented on Jan 28, 2020

    @dhalenok
    Contributor

    @JukkaL I'd like to help with this issue but not quite sure about where to start, any suggestions?

  2. JukkaL commented on Feb 4, 2020

    @JukkaL
    CollaboratorAuthor

    @DenisOH Look for calls to argument_incompatible_with_supertype in mypy/checker.py to find the relevant code.

  3. Arshaan-256 commented on Feb 26, 2020

    @Arshaan-256

    @DenisOH Can I work on this?

  4. emmatyping commented on Feb 26, 2020

    @emmatyping
    Member

    @Arshaan-256 it looks like Denis has already made a PR for this!

  5. Arshaan-256 commented on Feb 26, 2020

    @Arshaan-256

    Oh! I am so sorry. I thought that the PR didn't work since the issue was still open. Sorry!

  6. dhalenok commented on Feb 26, 2020

    @dhalenok
    Contributor

    @Arshaan-256 I'm still waiting on that PR to be reviewed. However, if it's not good or needs improvement, feel free to take over the issue.

  7. added a commit that references this issue on Feb 16, 2023
    d586070
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions