GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — mypy is confused by property aliases · Issue #1934 · gitpython-developers/GitPython

mypy is confused by property aliases #1934

New issue
Copy link
New issue
Copy link
Closed
#1935
Closed
mypy is confused by property aliases#1934
#1935
Copy link
Labels
acknowledged

Description

@PatrickMassot
PatrickMassot
opened on Jun 24, 2024
Issue body actions

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?

Activity

  1. Byron
    added
    acknowledged
    on Jun 24, 2024
  2. Byron commented on Jun 24, 2024

    @Byron
    Byron
    on Jun 24, 2024
    Member
    More actions

    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.

  3. PatrickMassot
    added a commit that references this issue on Jun 24, 2024

    Change aliases to work around mypy issue.

    This issue will close once commit f96eb0c is merged into the 'main' branch.
    f96eb0c
  4. PatrickMassot commented on Jun 24, 2024

    @PatrickMassot
    PatrickMassot
    on Jun 24, 2024
    ContributorAuthor
    More actions

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

    Reacted by Sebastian Thiel
  5. Byron
    closed this as completedin #1935on Jun 24, 2024
  6. Byron
    closed this as completedin f96eb0con Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    acknowledged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.