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

Adds SLF001 to ruff - private member access #435

Merged
merged 9 commits into from
Aug 7, 2024

Conversation

BradyPlanden
Copy link
Member

@BradyPlanden BradyPlanden commented Aug 5, 2024

Description

This PR adds the SLF001 rule to ruff linting, ensuring private members are not accessed outside the defining class. At the same time, this PR fixes our current access of private members which break SLF001. The main changes include:

  • cost._evaluate and cost._evaluateS1 are renamed to cost.compute and cost.computeS1 for SLF001 and to align with their functionality.
  • Adds property functions for read-access on private objects, and setters if required.
  • AdamW.lambda renamed to AdamW.lam to avoid namespace clash with python lambda.
  • CONTRIBUTING.md has been updated for usage with SLF001

Issue reference

Fixes #434

Review

Before you mark your PR as ready for review, please ensure that you've considered the following:

  • Updated the CHANGELOG.md in reverse chronological order (newest at the top) with a concise description of the changes, including the PR number.
  • Noted any breaking changes, including details on how it might impact existing functionality.

Type of change

  • New Feature: A non-breaking change that adds new functionality.
  • Optimization: A code change that improves performance.
  • Examples: A change to existing or additional examples.
  • Bug Fix: A non-breaking change that addresses an issue.
  • Documentation: Updates to documentation or new documentation for new features.
  • Refactoring: Non-functional changes that improve the codebase.
  • Style: Non-functional changes related to code style (formatting, naming, etc).
  • Testing: Additional tests to improve coverage or confirm functionality.
  • Other: (Insert description of change)

Key checklist:

  • No style issues: $ pre-commit run (or $ nox -s pre-commit) (see CONTRIBUTING.md for how to set this up to run automatically when committing locally, in just two lines of code)
  • All unit tests pass: $ nox -s tests
  • The documentation builds: $ nox -s doctest

You can run integration tests, unit tests, and doctests together at once, using $ nox -s quick.

Further checks:

  • Code is well-commented, especially in complex or unclear areas.
  • Added tests that prove my fix is effective or that my feature works.
  • Checked that coverage remains or improves, and added tests if necessary to maintain or increase coverage.

Thank you for contributing to our project! Your efforts help us to deliver great software.

@BradyPlanden BradyPlanden changed the title Adds SLF001 to ruff - private object access Adds SLF001 to ruff - private member access Aug 5, 2024
Copy link

codecov bot commented Aug 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.51%. Comparing base (1eb8a7e) to head (d68a70d).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #435      +/-   ##
===========================================
- Coverage    98.52%   98.51%   -0.02%     
===========================================
  Files           46       46              
  Lines         2923     2960      +37     
===========================================
+ Hits          2880     2916      +36     
- Misses          43       44       +1     

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

@NicolaCourtier
Copy link
Member

Please can we rename the _evaluate functions to something like internal_evaluate? These functions are not designed to be called by the user as they do not perform any checks on the inputs and only run the model simulation under certain conditions.

@BradyPlanden
Copy link
Member Author

BradyPlanden commented Aug 5, 2024

Hi @NicolaCourtier, thanks for the comment. I am planning a quick follow-up PR on this to give those methods the checking they need (although, I think almost all of it is in-place already?). At the moment, they are computed through side-effects, which I will correct, and have them accept the object of signals with checking. I've opened an issue for us to discuss on: #436

Edit: If that's still an issue, I can revert here so that this PR isn't held.

@NicolaCourtier
Copy link
Member

Will review after #425 - where some of the logic regarding modification of the parameter sets is fixed.

Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

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

Thanks for this, @BradyPlanden – this is great and I didn't know such a rule existed for what I felt would be a manual task for a long day! I agree with the code changes largely (without having followed the discussion in #425). I do think CodeCov is flaky, especially when changing a private attribute to a public one – from its annotation in pybop/problems/design_problem.py, so I would suggest triggering it again just to see whether that resolves or if that's an actual dip in coverage that needs to be fixed.

CONTRIBUTING.md Show resolved Hide resolved
pybop/transformation/transformations.py Outdated Show resolved Hide resolved
tests/unit/test_transformations.py Outdated Show resolved Hide resolved
BradyPlanden and others added 2 commits August 6, 2024 12:52
Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>
@NicolaCourtier
Copy link
Member

Let's agree on a more informative name for _evaluate before merging.
#436 (comment)

@BradyPlanden
Copy link
Member Author

I don't think we need to resolve the naming for #436 before this can land, we'll just apply the agreed naming within the changes to #436. Just waiting for your review when you get a chance :)

Copy link
Member

@NicolaCourtier NicolaCourtier left a comment

Choose a reason for hiding this comment

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

Thanks for the discussion @BradyPlanden, I've added my comments.

pybop/models/base_model.py Show resolved Hide resolved
tests/unit/test_models.py Show resolved Hide resolved
examples/standalone/cost.py Show resolved Hide resolved
@BradyPlanden BradyPlanden merged commit 78dcca5 into develop Aug 7, 2024
29 of 30 checks passed
@BradyPlanden BradyPlanden deleted the add-private-object-linting branch August 7, 2024 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Linting private member access
3 participants