8000 [NOT READY FOR REVIEW] Update pre-commit to all files and Mypy setup by Ckk3 · Pull Request #247 · strawberry-graphql/strawberry-sqlalchemy · GitHub
[go: up one dir, main page]

Skip to content

[NOT READY FOR REVIEW] Update pre-commit to all files and Mypy setup #247

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

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

Conversation

Ckk3
Copy link
Contributor
@Ckk3 Ckk3 commented May 15, 2025

Description

This PR introduces a mypy configuration similar to the one used in the main Strawberry project, and integrates a type-checking step into the CI workflows to ensure type safety is enforced consistently across the codebase.

Additionally, I ran pre-commit on all files, as many had not been formatted previously and did not follow the project's linting architecture. This helps standardize the codebase and reduce noise in future diffs.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Summary by Sourcery

Enforce consistent code formatting and enhance type safety by updating pre-commit hooks and Mypy setup, with a test to validate lint enforcement

Enhancements:

  • Add taplo-format hook to pre-commit config and reformat all files
  • Extend Mypy configuration with Pydantic plugin alongside Strawberry plugin

Tests:

  • Introduce a dummy test in mapper.py to enforce pre-commit linting

Copy link
Contributor
sourcery-ai bot commented May 15, 2025

Reviewer's Guide

This PR standardizes code formatting by updating the pre-commit setup to include the Taplo TOML formatter and reformatting all files, enhances type safety by extending the mypy configuration with the pydantic plugin, and adds a dummy function to enforce lint/pre-commit checks.

File-Level Changes

Change Details Files
Extend pre-commit configuration and reformat codebase
  • Added Taplo TOML formatter hook to pre-commit config
  • Ran pre-commit formatting across all files to align with lint rules
.pre-commit-config.yaml
Enhance type checking with pydantic plugin
  • Modified mypy.ini to include pydantic.mypy alongside the existing plugin
  • Targeted project source directory for consistent type checks
mypy.ini
Introduce dummy lint enforcement test
  • Added test_without_pre_commit function to validate pre-commit enforcement
src/strawberry_sqlalchemy_mapper/mapper.py

Assessment against linked issues

Issue Objective Addressed Explanation
#239 Add a mypy setup similar to the main strawberry project.
#239 Add a check to CI workflows to ensure type checking is enforced consistently.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@Ckk3 Ckk3 marked this pull request as ready for review May 15, 2025 15:54
@botberry
Copy link
Member
botberry commented May 15, 2025

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


This release does not introduce any new features or bug fixes. It focuses solely on internal code quality improvements.

Changes:

  • Added mypy configuration aligned with the main Strawberry project.
  • Enforced type checking via CI to ensure consistency.
  • Ran pre-commit across all files to standardize formatting and follow the project's linting architecture.

These changes aim to improve maintainability and ensure better development practices moving forward.

Copy link
Contributor
@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Ckk3 - I've reviewed your changes - here's some feedback:

  • Remove the test_without_pre_commit dummy function before merging, as it’s only intended to trigger lint failures.
  • Add a mypy type‐checking step to your CI workflows (e.g. GitHub Actions) to ensure the new mypy.ini is actually enforced.
  • Make sure the pydantic mypy plugin is added to the project’s dev dependencies so mypy can load it successfully.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟡 Testing: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

8000
@@ -883,7 +883,8 @@ def interface(self, model: Type[BaseModelType]) -> Callable[[Type[object]], Any]
):
raise InterfaceModelNotPolymorphic(model)
return self.type(model, make_interface=True)

def test_without_pre_commit():
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (testing): Unexpected test method inside mapper – remove or relocate

That test method on the mapper class lacks a self parameter and will break the API—remove it or move it to the proper test suite.

Copy link
codspeed-hq bot commented May 15, 2025

CodSpeed Performance Report

Merging #247 will not alter performance

Comparing Ckk3:run-precommit-in-all-files (4e54534) with main (7f2cbaf)

Summary

✅ 1 untouched benchmarks

@codecov-commenter
Copy link
codecov-commenter commented May 15, 2025

Codecov Report

Attention: Patch coverage is 0% with 18 lines in your changes missing coverage. Please review.

Project coverage is 88.94%. Comparing base (7f2cbaf) to head (4e54534).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #247      +/-   ##
==========================================
- Coverage   89.94%   88.94%   -1.01%     
==========================================
  Files          17       17              
  Lines        1939     1953      +14     
  Branches      141      141              
==========================================
- Hits         1744     1737       -7     
- Misses        123      141      +18     
- Partials       72       75       +3     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Ckk3 Ckk3 changed the title Update pre-commit to all files and Mypy setup [NOT READY FOR REVIEW] Update pre-commit to all files and Mypy setup May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add mypy setup like the main strawberry project
3 participants
0