Skip to content

Fixing pre-commit on Windows (disable warns for unused ignores) #1096

@vidartf

Description

@vidartf

Problem

  1. The mypy type checks for jupyter_server are currently *nix only. E.g. it will fail when trying to access socket.AF_UNIX when on windows. Using assert sys.platform != 'win32' as recommended for platform specific code doesn't seem to work?
  2. For the Windows specific code, we have type: ignore comments on them. Since we use a strict config, this will fail with error: Unused "type: ignore" comment on Windows. Note that it is not currently possible to ignore "unused ignore" errors: Cannot silence "unused 'type: ignore'" in version specific code python/mypy#8823
  3. The out-of-the-box pre-commit integrations with git do not work on Windows: Add sys.executable escapes on Windows pre-commit/pre-commit#2613 (this can be fixed manually by each user by editing the git hooks file)
  4. If you use the core.autocrlf=true setting, some linters (e.g. mdformat) will aggressively "fix" line endings, although git will subsequently fix it back when you do git add.

Proposed Solution

For 1. and 2.:

  • Add type: ignore comments on all OS-specific bits, and use flag warn_unused_ignores = False.
  • Run mypy on Windows CI as well to avoid future breakages.

For 3., hopefully the PR gets accepted and released. If not, we can maybe add a separate instruction to the docs.

For 4., we can maybe add another run of end-of-line-fixer to the end of the pre-commit config? That way any mess that e.g. the mdformat extension makes will be rectified again. Not really critical, but nice-to-have.

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