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

Apply refurb/ruff rule FURB142 #12240

Merged
merged 1 commit into from
Apr 9, 2024

Conversation

DimitriPapadopoulos
Copy link
Contributor

Subject: Apply refurb/ruff rule FURB142

Feature or Bugfix

  • Refactoring

Purpose

Fix this issue:

FURB142 Use of `set.add()` in a for loop

Relates

@chrisjsewell
Copy link
Member

Similar to #11849 (comment)

@DimitriPapadopoulos
Copy link
Contributor Author

Actually FURB142 is available in preview mode:

$ ruff check --select FURB142 --preview
sphinx/builders/__init__.py:317:9: FURB142 [*] Use of `set.add()` in a for loop
    |
315 |           doccount = len(updated_docnames)
316 |           logger.info(bold(__('looking for now-outdated files... ')), nonl=True)
317 |           for docname in self.env.check_dependents(self.app, updated_docnames):
    |  _________^
318 | |             updated_docnames.add(docname)
    | |_________________________________________^ FURB142
319 |           outdated = len(updated_docnames) - doccount
320 |           if outdated:
    |
    = help: Replace with `.update()`

Found 1 error.
[*] 1 fixable with the `--fix` option.
$ 

It should land in standard mode in upcoming versions of ruff. I am applying the rule so that the issue doesn't arise in the future. Additionally, the fix makes total sense.

[FURB142]: Replace `for x in y: s.add(docname)` with `s.update(y)`
@chrisjsewell
Copy link
Member

Actually FURB142 is available in preview mode

we also have preview=true, its just that it is not available in ruff==0.3.4
We can't update to 0.3.5 yet though, because of astral-sh/ruff#10724, but I'm sure 0.3.6 will be right around the corner 😄

@AA-Turner AA-Turner merged commit dbedb52 into sphinx-doc:master Apr 9, 2024
22 checks passed
@DimitriPapadopoulos DimitriPapadopoulos deleted the FURB142 branch April 9, 2024 18:33
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 10, 2024
@AA-Turner AA-Turner added this to the 7.3.0 milestone Jul 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants