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

Make some ruff fixes #8154

Merged
merged 4 commits into from
Mar 1, 2023
Merged

Make some ruff fixes #8154

merged 4 commits into from
Mar 1, 2023

Conversation

cclauss
Copy link
Member

@cclauss cclauss commented Feb 21, 2023

Describe your change:

ruff --select=RET501,RET502,RET503,SIM101,SIM102,SIM108,SIM109,SIM110,SIM117,SIM118,SIM201,SIM300,PD002,RUF005 --fix .

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@cclauss cclauss requested a review from dhruvmanila as a code owner February 21, 2023 16:59
@algorithms-keeper algorithms-keeper bot added awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files tests are failing Do not merge until tests pass labels Feb 21, 2023
@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Feb 21, 2023
Copy link
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

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

Looks good. There's just one thing I noticed which is that some places have explicit return None while others implicit return. I think we should adopt one or the other. What do you think?

@algorithms-keeper algorithms-keeper bot removed the awaiting reviews This PR is ready to be reviewed label Mar 1, 2023
@cclauss
Copy link
Member Author

cclauss commented Mar 1, 2023

Those rules cover different situations: implicit returns and unnecessary returns. Sometimes return None should be added and other times return None should be removed. So let's follow the modifications that the rules recommend.

Code Name Description Fix?
RET501 unnecessary-return-none Do not explicitly return None in function if it is the only possible return value 🛠
RET502 implicit-return-value Do not implicitly return None in function able to return non-None value 🛠
RET503 implicit-return Missing explicit return at the end of function able to return non-None value 🛠

@dhruvmanila
Copy link
Member

The rules exists, but it depends on the project, the maintainers and the audience through which the choice of rules need to be made. Just because a rule exist, doesn't mean it's a necessary thing to do.

This is what I think but it's upto you. If you think it's fine, then ok, but I think consistency matters.

@cclauss
Copy link
Member Author

cclauss commented Mar 1, 2023

I think that the rules make sense as they are.

For functions that never return a value, it is unnecessary to add an extra line at the end.
For functions that return a value, they should not implicitly return None (explicit is better than implicit).

@cclauss cclauss merged commit 64543fa into TheAlgorithms:master Mar 1, 2023
@cclauss cclauss deleted the ruff-fixes branch March 1, 2023 16:34
Cjkjvfnby pushed a commit to Cjkjvfnby/Python that referenced this pull request Mar 13, 2023
* Make some ruff fixes

* Undo manual fix

* Undo manual fix

* Updates from ruff=0.0.251
sedatguzelsemme pushed a commit to sedatguzelsemme/Python that referenced this pull request Mar 19, 2023
* Make some ruff fixes

* Undo manual fix

* Undo manual fix

* Updates from ruff=0.0.251
@isidroas isidroas mentioned this pull request Jan 25, 2025
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This PR modified some existing files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants