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

ci: add mypy for static type checking #1101

Merged
merged 1 commit into from
Feb 21, 2025
Merged

ci: add mypy for static type checking #1101

merged 1 commit into from
Feb 21, 2025

Conversation

leseb
Copy link
Contributor

@leseb leseb commented Feb 14, 2025

What does this PR do?

  • Enable mypy to run in the CI on a subset of the repository
  • Fix a few mypy errors
  • Run mypy from pre-commit

Signed-off-by: Sébastien Han [email protected]

Test Plan

[Describe the tests you ran to verify your changes with result summaries. Provide clear instructions so the plan can be easily re-executed.]

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Feb 14, 2025
@leseb leseb force-pushed the mypyy branch 2 times, most recently from 461e5cc to d45030d Compare February 14, 2025 11:51
@ashwinb
Copy link
Contributor

ashwinb commented Feb 14, 2025

Hm, this one is a biggy. I am OK with CI running this but local pre-commits should be much faster or at least there should be an option for a developer to avoid adding this all the time. Do you know how much additional time it ends up taking?

@ashwinb
Copy link
Contributor

ashwinb commented Feb 14, 2025

We do need to add some light type checking for sure though

@leseb
Copy link
Contributor Author

leseb commented Feb 14, 2025

Hm, this one is a biggy. I am OK with CI running this but local pre-commits should be much faster or at least there should be an option for a developer to avoid adding this all the time. Do you know how much additional time it ends up taking?

On my local machine, it takes a few extra seconds. The initial run is longer due to cache initialization, but it’s not too bad. Plus, since we’re skipping most of the codebase, the impact is minimal.

EDIT: also, while running pre-commit before pushing is recommended, it's still optional, if triggered from a git hook, one can still use --no-verify to skip it. I personally, don't run it for every commit, but only before pushing as a pre-push git hook.

requirements.txt Outdated
@@ -12,7 +12,7 @@ distro==1.9.0
exceptiongroup==1.2.2 ; python_full_version < '3.11'
filelock==3.17.0
fire==0.7.0
fsspec==2024.12.0
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it's "fine" though probably has nothing to do with mypy enablement. :)

Copy link
Contributor

@ashwinb ashwinb left a comment

Choose a reason for hiding this comment

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

ok let's do this :) I have a minor nit about the setup of the pre-commit hook. I don't think we should do a uv sync all the time unconditionally.

hooks:
- id: mypy
name: mypy
entry: bash -c 'uv sync --extra dev && uv run mypy'
Copy link
Contributor

Choose a reason for hiding this comment

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

can this just be uv run mypy? see the pre-commit entry added by @bbrowning as an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, thanks!

# type: Literal["custom"] = "custom"
# validator_class: str
class CustomType(BaseModel):
pylint: disable=syntax-error
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed if all of this is inside a string? Why was it even needed to be changed from a comment to a quoted string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mypy flagged type: Literal["custom"] = "custom" as an issue, even though it was inside a comment. Wrapping the block in a docstring made it invisible to MyPy, preventing the error.

@@ -21,6 +19,13 @@ class WebMethod:
method: Optional[str] = None


class HasWebMethod(Protocol):
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

# # honor excludes by not following there through imports
follow_imports = "silent"
exclude = [
# As we fix more and more of these, we should remove them from the list
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@ashwinb ashwinb added this to the v0.1.4 milestone Feb 20, 2025
- Enable mypy to run in the CI on a subset of the repository
- Fix a few mypy errors
- Run mypy from pre-commit

Signed-off-by: Sébastien Han <[email protected]>
@ashwinb ashwinb merged commit 9bbe346 into meta-llama:main Feb 21, 2025
3 checks passed
@leseb leseb deleted the mypyy branch February 24, 2025 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants