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

Create rule S7156 #4491

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Create rule S7156 #4491

wants to merge 3 commits into from

Conversation

github-actions[bot]
Copy link
Contributor

You can preview this rule here (updated a few minutes after each push).

Review

A dedicated reviewer checked the rule description successfully for:

  • logical errors and incorrect information
  • information gaps and missing content
  • text style and tone
  • PR summary and labels follow the guidelines

Copy link
Contributor

@joke1196 joke1196 left a comment

Choose a reason for hiding this comment

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

This is a good first draft, but don't hesitate to give more details for example about what has changed from Python 3.12 to 3.13, why is it an issue now and it was not before etc...

@@ -0,0 +1,78 @@
:object_replacement_protocol: https://docs.python.org/3/library/copy.html#object.__replace__

Copy link
Contributor

Choose a reason for hiding this comment

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

Usually here we do give a small description. Something like this rule raises an issue when copy.replace is used on an incorrect type. It is optional but I think it is nice if we have rule that all have follow a similar structure.

Comment on lines 5 to 6
Calling ``++copy.replace(...)++`` with an argument of an unsupported type will raise an ``++TypeError++``.
Types supported by ``++copy.replace(...)++`` must implement the {object_replacement_protocol}[replace protocol].
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a good start, but you should write the rule thinking the person reading it sees .replace for the first time. Maybe glance a bit at the other rules, the numpy or pandas rules. Also you could see with the rules for Java they usually have a nicely detailed WHY.


== How to fix it

If the argument passed in is a class defined in this project then implementing the {object_replacement_protocol}[replace protocol] by defining the ``++__replace__++`` method.
Copy link
Contributor

Choose a reason for hiding this comment

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

Bear in mind that the section How to fix and Why is it an issue are on different tab. So it is best to treat them as if the user did not read the previous section. So here for example it would be better to go with If the argument passed to the replace method.... Also in this section you can be more assertive. Instead of then implementing... you could go with to fix the issue, implement the protocol...

...

a = AClass()
b = copy.replace(a) # Noncompliant
Copy link
Contributor

Choose a reason for hiding this comment

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

When commenting with # Noncompliant it would be good to also say why. So Noncompliant: the class A does not implement...


== Resources
=== Documentation
* https://docs.python.org/3/library/copy.html#copy.replace
Copy link
Contributor

Choose a reason for hiding this comment

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

You can find how to format these sections and links in the docs folder . There are also a few guidelines available in the docs of sonarsource

* ``++inspect.Signature++``, ``++inspect.Parameter++``
* ``++types.SimpleNamespace++``
* https://docs.python.org/3/reference/datamodel.html#code-objects[code objects]

Copy link
Contributor

Choose a reason for hiding this comment

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

I would just add a section about exceptions saying that this rule only raises for Python 3.13.


== Why is this an issue?

Calling ``++copy.replace(...)++`` with an argument of an unsupported type will raise an ``++TypeError++``.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be a good idea to start by stating that this is for Python 3.13. i.e.: In Python 3.13 the copy.replace...

@Seppli11 Seppli11 force-pushed the rule/add-RSPEC-S7156 branch 2 times, most recently from 55577ac to 67f9f22 Compare November 13, 2024 13:24
Copy link

Quality Gate passed Quality Gate passed for 'rspec-tools'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Copy link

Quality Gate passed Quality Gate passed for 'rspec-frontend'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants