Skip to content

pre-commit hook for mypy fails #1539

Closed

Description

@antti-mikael

Description of the problem, including code/CLI snippet

$ git status --short
M  gitlab/v4/objects/container_registry.py
$ git commit
black....................................................................Passed
flake8...................................................................Passed
isort....................................................................Passed
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

gitlab/v4/objects/ldap.py:20: error: Function is missing a type annotation
gitlab/v4/objects/repositories.py:15: error: Function is missing a type annotation
gitlab/v4/objects/repositories.py:38: error: Function is missing a type annotation
...

Maybe the mypy hook could be configured to ignore missing annotations or warn instead of erring -- at least until the annotations are in place:

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 80c8fb8..c69e125 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -24,3 +24,4 @@ repos:
     rev: v0.812
     hooks:
       - id: mypy
+        args: ["--allow-untyped-defs"]

Expected Behavior

I'm able to make commits for files that don't have type annotations.

Actual Behavior

mypy fails for missing function annotations.

Specifications

  • python-gitlab version: master (85713bb)
  • API version you are using (v3/v4): N/A
  • Gitlab server version (or gitlab.com): N/A

Activity

  1. nejch commented on Jul 1, 2021

    @nejch
    Member

    Thanks for opening the issue, we already had this reported but i forgot to open one!

    Yeah, that would help although then people might get CI failures because pre-commit wouldn't catch issues in files where it already should check for it.

    I think a better solution would be to replace the files list in our config with an exclude pattern because currently the pre-commit hook is probably overriding the default files list and hence fails.

    https://mypy.readthedocs.io/en/stable/config_file.html#confval-files

    [mypy]
    files = gitlab/*.py,gitlab/v4/cli.py,gitlab/v4/objects/projects.py

    I will test this tonight but feel free to already open a PR if you get it to work :)

  2. antti-mikael commented on Jul 1, 2021

    @antti-mikael
    ContributorAuthor

    Sorry, I totally missed the .mypy.ini. I'll see if I have the time to fiddle with this.

  3. antti-mikael commented on Jul 19, 2021

    @antti-mikael
    ContributorAuthor

    I think a better solution would be to replace the files list in our config with an exclude pattern because currently the pre-commit hook is probably overriding the default files list and hence fails.

    After some some digging around it seems that exclude has the same problem as files: positional command line arguments will override the configuration. From mypy's docs:

    Note that [--exclude] flag only affects recursive discovery, that is, when mypy is discovering files within a directory tree or submodules of a package to check. If you pass a file or module explicitly it will still be checked.

    One solution would be to mirror the files pattern in the pre-hook config. It's not a nice solution but it's the only one I have managed to come up with so far.

  4. nejch commented on Aug 1, 2021

    @nejch
    Member

    I have something in #1562, not the prettiest either but it should now take whatever args pre-commit throws at it and ignore errors where needed.

  5. locked as resolved and limited conversation to collaborators on Aug 29, 2022
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions