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

(RUF012) Fixed mutable class Defaults- Task 4 #10278

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

drona-gyawali
Copy link
Contributor

@drona-gyawali drona-gyawali commented Jan 5, 2025

Part of #10196
NOTE: These are NOT automated changes, they are done by hand

  • Prevents accidental modifications of mutable class attributes at the instance level.
  • Aligns with project style guidelines enforced by Ruff.

Technical

  • Updated mutable class attributes in 6 files to use typing.ClassVar for clarity and correctness.
  • Added ClassVar annotations to mutable class attributes to ensure they are treated as class-level attributes.
  • Ensured proper type hints for clarity and type safety.

Testing

Ran ruff check --select RUF012 to confirm no further warnings.

Screenshot

N/A

Stakeholders

@RayBB

Copy link
Collaborator

@RayBB RayBB left a comment

Choose a reason for hiding this comment

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

Looks great to me.
Now we need staff to review/merge.

@RayBB RayBB added the Needs: Staff / Internal Reviewed a PR but don't have merge powers? Use this. label Jan 5, 2025
@RayBB RayBB added Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] and removed Needs: Staff / Internal Reviewed a PR but don't have merge powers? Use this. labels Jan 15, 2025
@RayBB
Copy link
Collaborator

RayBB commented Jan 16, 2025

@drona-gyawali I looked at this with Drini and we realized we probably don't want all these values to be mutable.
Can you review and add non-mutable options to this and the other PRs (unless it needs to be mutable).

See https://docs.astral.sh/ruff/rules/mutable-class-default/

@drona-gyawali
Copy link
Contributor Author

I'll make the necessary changes and let you know once they're ready for review.

@github-actions github-actions bot removed the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Jan 16, 2025
@drona-gyawali
Copy link
Contributor Author

Hi @RayBB , I made changes in 4 files, but in this PR, there are 6 files, and I left two files unchanged: tests/solr/test_update.py and tests/solr/updater/test_work.py because I was a bit confused about whether to keep mutable defaults or immutable defaults. As of now, these two files are following mutable defaults, but I am unsure what to do. Please guide me.

@RayBB
Copy link
Collaborator

RayBB commented Jan 16, 2025

@drona-gyawali it looks like a good start.
I see that Mapping is deprecated so try MappingProxyType instead.

As far as the ones if you're not sure if they're mutable I'd say:

  1. Check if they're being changed somewhere, if so point to where and we can look closer. They probably shouldn't be changed.
  2. You can also try just changing them to be immutable and maybe mypy will complain if they're not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting Review/Merge from Staff
Development

Successfully merging this pull request may close these issues.

2 participants