Skip to content

Conversation

@nucli-vicky
Copy link
Contributor

@nucli-vicky nucli-vicky commented Jan 4, 2026

This PR adds rules F821-823:

  • F821: undefined name not allowed (very useful for catching bugs, see for instance the missing warnings import)
  • F822: everything in __all__ should exist. Critical, but also seems a bit too evident, might not be worth it to have it as a rule? Fine with removing it.
  • F823: don't allow "variable used before assignment" --> also good for catching bugs.

I think adding these rules makes sense and does not significantly raise the bar for contributions, while still being good for preventing bugs, which is the philosophy agreed upon in #539. In recent months, a few bugs in main were already identified manually and fixed, which would have been caught by these rules too, e.g. part of the small fixes in #981 , #955, so these rules do correspond with real bugs which occur during development, not some hypothetical scenarios (note also the change in optim_iterator fixes a live bug (albeit small).

Checks to be done before submitting your PR

  • python3 -m pytest deepinv/tests runs successfully.
  • black . runs successfully.
  • make html runs successfully (in the docs/ directory).
  • Updated docstrings related to the changes (as applicable).
  • Added an entry to the changelog.rst.

@nucli-vicky
Copy link
Contributor Author

Just realized enabling all the F rules is already worked on in #705. However, as already mentioned by @jscanvic , it does make sense to split these up into smaller PRs, and I believe these rules have high signal; anything caught should be an actual bug that can raise errors.

Copy link
Collaborator

@Andrewwango Andrewwango left a comment

Choose a reason for hiding this comment

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

Thanks Vicky! This is super helpful and one step closer...

@Andrewwango Andrewwango merged commit a72df71 into deepinv:main Jan 5, 2026
7 checks passed
@nucli-vicky nucli-vicky deleted the undefined-names branch January 6, 2026 09:10
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.

2 participants