PyBaMM icon indicating copy to clipboard operation
PyBaMM copied to clipboard

Fixed mypy sp check guidelines

Open Rishab87 opened this issue 10 months ago • 8 comments

Description

Fixing mypy sp check guidelines

Some major changes I did:

  • In src/pybamm/expression_tree/binary_operators.py I've replaced self.__ class __ in line 131 with new_instance because earlier when we were using self.__ class __ it showed a third arg was not getting passed:

    error: Missing positional argument "right_child" in call to "BinaryOperator"  [call-arg]
    

    but this function was always getting called from instance of its child classes which don't need to pass 3 arguments, so i thought it was better to make a new_instance method which can be overrided in child classes

  • In src/pybamm/expression_tree/broadcasts.py I've forced child classes of Broadcast to implement _unary_new_copy because earlier we were using self.broadcast_domain in this function in Broadcast class but it does not have any attribute self.broadcast_domain, this function was only getting called by instance of their child classes which has self.broadcast_domain property.

  • In tests/unit/test_expression_tree/test_operations/test_copy.py in test_symbol_create_copy_new_children test I've added an extra argument perform_simplifications=False to create_copy method to ensure 100% coverage of new_instance methods.

Related to #3489

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #)

Important checks:

Please confirm the following before marking the PR as ready for review:

  • [x] No style issues: nox -s pre-commit
  • [x] All tests pass: nox -s tests
  • [x] The documentation builds: nox -s doctests
  • [x] Code is commented for hard-to-understand areas
  • [ ] Tests added that prove fix is effective or that feature works

Rishab87 avatar Mar 02 '25 07:03 Rishab87

Still 25 mypy errors are left, drafting this so that its easier to communicate changes

Rishab87 avatar Mar 02 '25 07:03 Rishab87

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 98.70%. Comparing base (8f91615) to head (e1b1aec). Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4887      +/-   ##
===========================================
- Coverage    98.71%   98.70%   -0.01%     
===========================================
  Files          304      304              
  Lines        23509    23542      +33     
===========================================
+ Hits         23207    23238      +31     
- Misses         302      304       +2     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Mar 02 '25 12:03 codecov[bot]

It would be great to have repo-review as a pre-commit hook! @agriyakhetarpal maybe you can create a new independent issue for that?

Saransh-cpp avatar Mar 02 '25 13:03 Saransh-cpp

I've changed the PR description to related to and I also think it would be great to have a pre-commit hook for sp-check-guidelines, I'll investigate its speed after this PR is done

Rishab87 avatar Mar 03 '25 04:03 Rishab87

I've fixed the remaining errors too

Rishab87 avatar Mar 03 '25 08:03 Rishab87

@agriyakhetarpal Thanks for the review, I've left comments for the major changes, should I write these major changes in PR description too?

Rishab87 avatar Mar 09 '25 05:03 Rishab87

@agriyakhetarpal Thanks for the review, I've left comments for the major changes, should I write these major changes in PR description too?

Yes, please do!

agriyakhetarpal avatar Mar 10 '25 06:03 agriyakhetarpal

@agriyakhetarpal I've updated the PR description, can you please review it?

Rishab87 avatar Mar 10 '25 09:03 Rishab87