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

mypy is confused by property aliases #1934

Closed
PatrickMassot opened this issue Jun 24, 2024 · 2 comments · Fixed by #1935
Closed

mypy is confused by property aliases #1934

PatrickMassot opened this issue Jun 24, 2024 · 2 comments · Fixed by #1935

Comments

@PatrickMassot
Copy link
Contributor

Thank you very much for this very useful python package. Unfortunately mypy is very confused by property aliases such as

    @property
    def references(self) -> "IterableList[Reference]":
        """A list of :class:`~git.refs.reference.Reference` objects representing tags,
        heads and remote references.

        :return:
            ``git.IterableList(Reference, ...)``
        """
        return Reference.list_items(self)

    # Alias for references.
    refs = references

that can be found in git/repo/base.py or the analogous alias branches for heads. See python/mypy#6700

You can reproduce the issue with the following test.py:

from git.repo import Repo

repo = Repo()
for branch in repo.branches:
    print(branch)

about which mypy says:

test.py:4: error: "Callable[[], IterableList[Head]]" has no attribute "__iter__" (not iterable)  [attr-defined]
Found 1 error in 1 file (checked 1 source file)

I am not aware of any fix that would not uglify the code here, and that mypy issue doesn’t seem likely to see improvement in the near future. This is sad, but doing all the work to add type annotations and still having users facing incomprehensible error messages in perfectly legitimate code is also sad.

Could you please tell me whether you would welcome a PR “fixing” this?

@Byron
Copy link
Member

Byron commented Jun 24, 2024

Thanks for reporting! Yes, please feel free to submit a PR with a fix, as long as it's not done by a breaking change in the current API.

If the API needs to change, an alternative one to the what already exists can be provided. Maybe, and this is my hope, the typing itself can be improved.

@PatrickMassot
Copy link
Contributor Author

Ok, I submitted a minimal fix. There is no API change here, only more verbose code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants