Skip to content

Reuse of “exc” name in __init__.py confuses Pylint #1587

Description

@Hawk777

It’s not entirely clear how one is supposed to name GitPython’s exceptions:

  • According to the API reference, they live in the git.exc module.
  • In __init__.py, the very first line does from git.exp import *, meaning they can actually just be referenced in the git module instead if one wishes (is that intentional/public knowledge?).

Then, further down __init__.py, there are two places where except Something as exc is done in module-level code. While those won’t execute on success (and will prevent the module from importing on failure), they do confuse Pylint: if I try to except git.exc.InvalidGitRepositoryError in my own code and then lint it, Pylint complains that Instance of 'GitError' has no 'InvalidGitRepositoryError' member, because it believes the name git.exc itself might actually be an instance of GitError (as it would be if this except clause were taken).

Is it intended that we refer to exception classes from git rather than git.exc? If so, could the documentation be updated? If not—if we are not supposed to know about the from git.exc import *—could the variable names used in those except blocks be modified to not collide with a submodule name?

Activity

  1. Byron commented on May 13, 2023

    @Byron
    Member

    No matter what the intention was, it appears the documentation could be updated to mention these can be imported using multiple paths.

    Further, it appears except E as exc can be fixed as well, and a contribution for all of that is definitely welcome.

  2. Hawk777 commented on May 14, 2023

    @Hawk777
    ContributorAuthor

    No matter what the intention was, it appears the documentation could be updated to mention these can be imported using multiple paths.

    I was thinking, if it wasn’t intentional, it would be better not to document it since if it’s documented, people might rely on it, but if it’s not documented, it’s OK to break it in future versions. So I figured it was up to you.

    Further, it appears except E as exc can be fixed as well, and a contribution for all of that is definitely welcome.

    PEP 8 appears to suggest using a leading underscore for module-private global variables; is that your preference here? If so I can throw together an MR that does that.

  3. Byron commented on May 15, 2023

    @Byron
    Member

    I think the only fix possible is to turn … as exc into … as _exc, and a PR is very welcome. Thanks for your help.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions