oppia: Fix pylint problems

The goal of this issue is to enable some pylint rules that we disabled while doing the Python 3 migration.

Steps to follow to create a PR:

  1. Ask @seanlip to assign you to one of the items below
  2. Remove the assigned item from the .pylintrc
  3. Run python -m scripts.linters.pre_commit_linter --only-check-file-extensions=py --path=core --verbose to check existing issues in the codebase. (This can take 3-5 mins mins to complete.)
  4. If the above script takes too much time or you have a slow machine then consider pushing the code to GitHub and GitHub actions will run these checks for you.
  5. Fix all the issues found by running the above command.
  6. Commit all the changes and create a PR.

Example PRs: #14474

Remove some disables from the .pylintrc:

  • cyclic-import
  • consider-using-with (unclaimed: for reference, see previous PR by @anjaist #18139)

Refactor custom validators that are not working correctly:

  • #16366 (assignments tracked in linked issue)

Decided not to introduce:

  • consider-using-dict-items @mjsumpter
  • consider-using-f-string
  • super-with-arguments @jrvald
  • unnecessary-pass
  • arguments-renamed
  • import-outside-toplevel

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 122 (70 by maintainers)

Commits related to this issue

Most upvoted comments

Hello @U8NWXD, I’d like to be assigned consider-using-with. Here are the files that would be affected:

core/controllers/profile_test.py
core/controllers/editor_test.py
core/domain/exp_services_test.py

Example change: before:

zf_saved = zipfile.ZipFile(io.BytesIO(data.body))
assert zf_saved[...]

after:

with zipfile.ZipFile(io.BytesIO(data.body)) as zf_saved:
    assert zs_saved[...]

Additionally, I’d add a single # pylint: disable=consider-using-with line here, as the usage of this function is always using a with statement and we do only casting here. I’m not sure if there is an alternative way of doing this apart from changing the way this utils.open_file func is used.

Hi! @josieecook Per the guidance at https://github.com/oppia/oppia/wiki/Contributing-code-to-Oppia#choosing-a-good-first-issue, please provide an explanation of what your PR will do (with names of files you’re changing, what you plan to change in each file, etc.). If it looks good, we can assign you to this issue.

@prakhar1144 Are you working on this?

@richard-johansson I think you can work on consider-using-with if @prakhar1144 doesn’t reply.

@PietroFracCab Done, please create a PR.

@PietroFracCab Hey, sorry for delay in reply, can you please give me comment access to your doc? I have some suggestions.

@prakhar1144 Done.

@anurag629 Please pick a different issue, everything is assigned here.

Hey, @vojtechjelinek assign me if any issue is available and also tell me how to proceed with same.

Thanks

@Shaman20 That one might be a bit complicated, I recommend picking one from the first list.

@mjsumpter I’ve assigned you consider-using-dict-items

@Manan-Rathi Create one PR with all the changes i.e, enabling both the rules and fixing existing lint issues in the codebase. (Considering the number of changed files in the PR won’t be > 50)

Hi @Manan-Rathi, I’ve assigned you to no-else-continue and no-else-raise!