Skip to content

Admin: Enable mypy during linting #12532

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

Merged
merged 1 commit into from
Apr 22, 2025
Merged

Conversation

bblommers
Copy link
Contributor

Motivation

With #12232 merged and the localstack package typed, it would be nice if the types are actually correct and verified.

This PR:

  1. Adds the plumbing to enable mypy for specific locations
  2. Fixes all typing-issues in those specific locations

Locations

I chose two locations to get this started:

  1. localstack.packages, just because I knew that was one of the areas where typing could be improved
  2. localstack.kinesis.packages because it's a downstream consumer, so we also verify the usage of the package-module

Changes

The Package class is now generic, and should be typed as Package[PackageInstaller]. This ensures that Package.get_installer() can return the correct subtype, like NodePackageInstaller, and that means that consumers can also safely call any methods that are specific to NodePackageInstaller.

Almost all calls to Package.get_installed_dir() now have a type: ignore added to them. The get_installed_dir-method can return str | None, but we assume downstream that it always returns a str.
Realistically, if that method does return None, it probably means that something went wrong during the download/installation, so we should be raising an error instead of returning None. For now, I've decided to type: ignore it instead of changing the behaviour (and potentially breaking other things).

@bblommers bblommers added the semver: patch Non-breaking changes which can be included in patch releases label Apr 16, 2025
@bblommers bblommers added this to the Playground milestone Apr 16, 2025
Copy link

github-actions bot commented Apr 16, 2025

S3 Image Test Results (AMD64 / ARM64)

  2 files    2 suites   8m 46s ⏱️
488 tests 438 ✅  50 💤 0 ❌
976 runs  876 ✅ 100 💤 0 ❌

Results for commit ac9fe3e.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Apr 16, 2025

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   1h 54m 57s ⏱️ + 1m 47s
4 373 tests ±0  4 016 ✅ ±0  357 💤 ±0  0 ❌ ±0 
4 375 runs  ±0  4 016 ✅ ±0  359 💤 ±0  0 ❌ ±0 

Results for commit ac9fe3e. ± Comparison against base commit 5e8dc09.

♻️ This comment has been updated with latest results.

@bblommers bblommers force-pushed the admin/add-mypy-to-lint-step branch 2 times, most recently from 0d6f920 to c484266 Compare April 17, 2025 08:21
@bblommers bblommers force-pushed the admin/add-mypy-to-lint-step branch 2 times, most recently from de378b1 to cec8172 Compare April 17, 2025 10:04
@bblommers bblommers marked this pull request as ready for review April 17, 2025 11:33
Copy link
Member

@alexrashed alexrashed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, the changes are looking great! It revives and extends the mypy config from back in the days! This might as well become infectious, which would be great, but this already helps code owners to enforce typing for their codebases! 💯
I think we should really try to make this as automated as possible, few things are more frustrating than a linting check failing in CI. They should be visible asap. :)

@@ -121,6 +121,7 @@ lint: ## Run code linter to check code style, check if formatte
($(VENV_RUN); python -m ruff check --output-format=full . && python -m ruff format --check --diff .)
$(VENV_RUN); pre-commit run check-pinned-deps-for-needed-upgrade --files pyproject.toml # run pre-commit hook manually here to ensure that this check runs in CI as well
$(VENV_RUN); openapi-spec-validator localstack-core/localstack/openapi.yaml
$(VENV_RUN); cd localstack-core && mypy --install-types --non-interactive
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: In my opinion, everything that is checked with make lint should also be enforced by the pre-commit hook. Is there a chance to add this command to the precommit config as well? Could be tricky with the isolated execution environment though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is tricky, but we can override the entry-point for the pre-commit hook, so it is possible. Updated the PR to include this, and verified locally that it works 👍

@bblommers bblommers force-pushed the admin/add-mypy-to-lint-step branch from cec8172 to 3c2d248 Compare April 18, 2025 09:26
@bblommers bblommers force-pushed the admin/add-mypy-to-lint-step branch from 3c2d248 to ac9fe3e Compare April 18, 2025 09:36
@bblommers bblommers requested a review from alexrashed April 18, 2025 10:58
Copy link
Member

@alexrashed alexrashed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thank for jumping on the comment and integrating mypy also in the precommit hooks! LGTM! 💯

@bblommers bblommers merged commit 96a0216 into master Apr 22, 2025
38 checks passed
@bblommers bblommers deleted the admin/add-mypy-to-lint-step branch April 22, 2025 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants