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

Add type hints and mypy config #1015

Merged
merged 8 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ env:
AWS_NO_SIGN_REQUEST: "1"

jobs:
type-checking:
name: Run Type Checking
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: 'pip' # caching pip dependencies
- run: pip install -r requirements/requirements.txt -r requirements/test.txt -r requirements/dev.txt
- name: Run mypy
run: mypy

# Increase rate limits for public registry
amazon-ecr-auth:
runs-on: ubuntu-latest
Expand Down
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ repos:
- id: cmake-lint
args:
- --suppress-decorations
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
hooks:
- id: mypy
name: Check types with mypy
language: system
entry: build/venv/bin/mypy
pass_filenames: false
11 changes: 5 additions & 6 deletions kart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import importlib
import logging
import os
import platform
import sys

L = logging.getLogger("kart.__init__")
Expand Down Expand Up @@ -40,17 +39,17 @@
)

try:
import _kart_env
import _kart_env # type: ignore[import]

L.debug("Found _kart_env configuration module")
except ImportError:
L.debug("No _kart_env configuration module found")
_kart_env = None

is_frozen = getattr(sys, "frozen", None) and hasattr(sys, "_MEIPASS")
is_darwin = platform.system() == "Darwin"
is_linux = platform.system() == "Linux"
is_windows = platform.system() == "Windows"
is_darwin = sys.platform == "darwin"
is_linux = sys.platform == "linux"
is_windows = sys.platform == "win32"

if is_darwin:
libsuffix = "dylib"
Expand Down Expand Up @@ -146,7 +145,7 @@ def _env_path(path):
os.environ["PATH"] = (
os.pathsep.join(path_extras) + os.pathsep + os.environ.get("PATH", "")
)
if is_windows:
if sys.platform == "win32":
os.add_dll_directory(prefix if is_frozen else os.path.join(prefix, "lib"))
# FIXME: git2.dll is in the package directory, but isn't setup for ctypes to use
_pygit2_spec = importlib.util.find_spec("pygit2")
Expand Down
6 changes: 4 additions & 2 deletions kart/annotations/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import logging
import threading

from typing import TypeAlias
import sqlalchemy

from kart.sqlalchemy.sqlite import sqlite_engine
Expand All @@ -13,7 +13,9 @@
from sqlalchemy.schema import CreateTable

L = logging.getLogger(__name__)
Base = declarative_base()

# TODO: remove this type ignore when we upgrade sqlalchemy to 2.0 and replace with DeclarativeBase
Base: TypeAlias = declarative_base() # type: ignore[valid-type]


class KartAnnotation(Base):
Expand Down
2 changes: 1 addition & 1 deletion kart/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def apply_patch(
"--ref",
default="HEAD",
help="Which ref to apply the patch onto.",
shell_complete=ref_completer,
shell_complete=ref_completer, # type: ignore[call-arg]
)
@click.option(
"--amend",
Expand Down
Loading
Loading