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

feat: Add mypy type checking #4863

Open
wants to merge 55 commits into
base: main
Choose a base branch
from
Open

Conversation

zachaysan
Copy link
Contributor

Changes

This adds mypy type checking. Existing failures have been grandfathered in and a helper script is run to compare failures against the predefined list. Mypy was also added into the pre-commit config and will run on any commits to python code.

How did you test this code?

I altered the predefined mypy list and saw a failure crop up when running pre-commit.

@zachaysan zachaysan requested a review from a team as a code owner November 25, 2024 16:55
@zachaysan zachaysan requested review from matthewelwell and removed request for a team November 25, 2024 16:55
Copy link

vercel bot commented Nov 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview Dec 17, 2024 4:47pm
flagsmith-frontend-preview ⬜️ Ignored (Inspect) Visit Preview Dec 17, 2024 4:47pm
flagsmith-frontend-staging ⬜️ Ignored (Inspect) Visit Preview Dec 17, 2024 4:47pm

@github-actions github-actions bot added the api Issue related to the REST API label Nov 25, 2024
Copy link
Contributor

github-actions bot commented Nov 25, 2024

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api-test:pr-4863 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-4863 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-4863 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-4863 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-4863 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-4863 Finished ✅ Results

@github-actions github-actions bot added the feature New feature or request label Nov 25, 2024
@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Nov 25, 2024
Copy link
Contributor

github-actions bot commented Nov 25, 2024

Uffizzi Ephemeral Environment deployment-58551

☁️ https://app.uffizzi.com/github.com/Flagsmith/flagsmith/pull/4863

📄 View Application Logs etc.

What is Uffizzi? Learn more!

Copy link

codecov bot commented Nov 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.39%. Comparing base (05ab7cf) to head (6dcff38).
Report is 29 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #4863    +/-   ##
========================================
  Coverage   97.38%   97.39%            
========================================
  Files        1189     1191     +2     
  Lines       41420    41526   +106     
========================================
+ Hits        40338    40444   +106     
  Misses       1082     1082            

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@matthewelwell matthewelwell left a comment

Choose a reason for hiding this comment

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

This seems like a decent enough solution to me but I have some general questions:

  1. What happens if we (perhaps inadvertently) resolve an existing issue. Based on the logic in your script, I guess we wouldn't know about it, right? Because we're just seeing what's left after we subtract the original errors from the new ones which wouldn't tell us anything about any that we've solved. It would obviously be great to incentivise resolving existing issues where we can.

  2. This approach works fine I guess, but another solution would have been to just add all of the distinct files into the exclude. Then every new file would need to conform to mypy, but changes to existing files wouldn't. I'm not sure how we could incentivise fixing the existing errors. (Note: I'm certainly not suggesting this is a better option, I'm just playing devil's advocate).

hooks:
- id: mypy-check
name: mypy check
entry: bash -c "cd api && poetry run python scripts/mypy_check.py"
Copy link
Contributor

Choose a reason for hiding this comment

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

Since I was looking at similar functionality yesterday (see here) , I am somewhat intrigued by this.

My understanding of pre-commit is that it passes the modified files into the command specified in entry, so the resulting command would look something like:

bash -c "cd api && poetry run python scripts/mypy_check.py" file1.py file2.py 

... which I would expect to just not work at all, or at least throw some sort of error?

Copy link
Contributor

Choose a reason for hiding this comment

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

@zachaysan I'm not sure the latest changes make any reference to this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've altered the script to run the files one at a time. I had to use git diff to list the target files of the commit because no matter what I tried to pass into the bash script it just wouldn't run with the automatic listed files. The good news is that we are now doing a mypy check on only the committed files.

api/mypy.ini Outdated Show resolved Hide resolved
@matthewelwell matthewelwell linked an issue Dec 2, 2024 that may be closed by this pull request
@khvn26 khvn26 force-pushed the feat/add_mypy_type_checking branch from c9b44d4 to c3e7907 Compare December 17, 2024 16:30
@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Dec 17, 2024
…b.com:Flagsmith/flagsmith into feat/add_mypy_type_checking
@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issue related to the REST API feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enforcing typing
4 participants