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

Investigate Python Unused Imports #3483

Closed
teymour-aldridge opened this issue Jun 1, 2020 · 30 comments · Fixed by #7413
Closed

Investigate Python Unused Imports #3483

teymour-aldridge opened this issue Jun 1, 2020 · 30 comments · Fixed by #7413
Labels
Good First Issue Easy issue. Good for newcomers. [managed] Lead: @cclauss Issues overseen by Chris (Python3 & Dev-ops lead 2019-2021) [managed] Priority: 3 Issues that we can consider at our leisure. [managed] python Pull requests that update Python code Type: Epic A feature or refactor that is big enough to require subissues. [managed] Type: Refactor/Clean-up Issues related to reorganization/clean-up of data or code (e.g. for maintainability). [managed]

Comments

@teymour-aldridge
Copy link

teymour-aldridge commented Jun 1, 2020

There are a lot of unused imports which clutter things.

Describe the problem that you'd like solved

Refactoring to remove all unused imports.

Proposal & Constraints

Remove all ununsed imports. This will reduce technical debt, decluttering things to make them clearer.

Additional context

UPDATE:
As per @cclauss's comments below, for detecting unused imports, we should really be running

python3 -m pip install flake8
flake8 --select=F401

Stakeholders

@cclauss @imskr

@teymour-aldridge teymour-aldridge added the Needs: Triage This issue needs triage. The team needs to decide who should own it, what to do, by when. [managed] label Jun 1, 2020
@mekarpeles
Copy link
Member

@teymour-aldridge could you help us with this one?

@mekarpeles mekarpeles added Lead: @mekarpeles Issues overseen by Mek (Staff: Program Lead) [managed] Priority: 3 Issues that we can consider at our leisure. [managed] Type: Refactor/Clean-up Issues related to reorganization/clean-up of data or code (e.g. for maintainability). [managed] Good First Issue Easy issue. Good for newcomers. [managed] and removed Needs: Triage This issue needs triage. The team needs to decide who should own it, what to do, by when. [managed] labels Jun 2, 2020
@imskr
Copy link
Contributor

imskr commented Jun 2, 2020

Work is in Progress refer #3447 As soon as this will get merged, I will land another PR.

@teymour-aldridge
Copy link
Author

I'd be happy to help. I'm a bit busy at the moment, but should have some time on the weekend.
To automatically catch these sort of errors it might be worth installing CodeClimate on the repository (which automatically reports code duplication, ununsed imports, overly complex functions, etc) as well as LGTM.com (which catches security bugs in open source). Both are free for open sorce software!

@cclauss
Copy link
Contributor

cclauss commented Jun 3, 2020

flake8 which we already run in our continuous integration can autodetect these issues.

Detection is not the problem. The problem is that no one is reviewing PRs so they sit open for months at a time. Let's not add CodeClimate as it is full of uncontrollable false positives.

@teymour-aldridge
Copy link
Author

Oh right. I may have jumped the gun a bit here. I'd be happy to work to try and help resolve some of these issues.

@ctorok
Copy link

ctorok commented Jun 23, 2020

Happy to help; need some guidance. These are the steps I would take?

  1. Clone the repository at https://github.com/internetarchive/openlibrary
  2. Run the query and get the results, https://lgtm.com/query/7596990423930761565/
  3. Remove offending import from file
  4. Commit back to repo

@cclauss
Copy link
Contributor

cclauss commented Jun 23, 2020

python3 -m pip install flake8
flake8 --select=F401

@Himanshunitrr
Copy link

Can I too work on this issue, sir?

@cclauss
Copy link
Contributor

cclauss commented Jul 11, 2020

Please refer to #3447... That must be reviewed and landed first.

@mekarpeles mekarpeles added the hacktoberfest Issues appropriate for Hacktoberfest participants label Oct 5, 2020
@SaravgiYash
Copy link
Contributor

SaravgiYash commented Oct 7, 2020

Hi, @cclauss @imskr I would like to work on this issue.

Can I remove unused imports from other files excluding code.py and conftest.py?

@SaravgiYash
Copy link
Contributor

@mekarpeles I started working on this issue, so I just want to know that is there a way to automatically remove unused imports or do I need to remove them manually.

@cclauss
Copy link
Contributor

cclauss commented Oct 8, 2020

CAUTION: Some imports are done for side effects so linters like flake8 may say they are not needed but things will break without them. Please do just a file or two per PR.

@SaravgiYash
Copy link
Contributor

SaravgiYash commented Oct 8, 2020

@cclauss I have removed unused imports till .\openlibrary\plugins\openlibrary\utils.py so should I create a PR and commit them 2 at a time? or create separate PR for each of them?

@SaravgiYash
Copy link
Contributor

@cclauss I would like to remove unused imports from other files as well. So should I first create a PR for unused Python standard library imports?

@cclauss
Copy link
Contributor

cclauss commented Oct 27, 2020

Should I first create a PR for unused Python standard library imports?

I thought that #3909 was that PR.

@SaravgiYash
Copy link
Contributor

SaravgiYash commented Oct 27, 2020

I thought that #3909 was that PR.

@cclauss I mean for other files (files after openlibrary/core/waitinglist.py).
I removed all unused imports till openlibrary/core/waitinglist.py and in PR #3909 I removed all standard unused imports till openlibrary/core/waitinglist.py.

@cclauss
Copy link
Contributor

cclauss commented Oct 27, 2020

OK. Please creating more PRs that only remove Python standard library imports. Once those are all landed, we can look at PRs for other imports.

@SaravgiYash
Copy link
Contributor

@cclauss As #3965 is merged should I remove other unused imports and commit them 2 files at a time?

@SaravgiYash
Copy link
Contributor

@cclauss Should I go ahead and remove other unused imports (Non-standard ones)

@cclauss
Copy link
Contributor

cclauss commented Nov 17, 2020

Sorry but not right now. These changes create issues that are quite difficult to find.

Right now we are trying to upgrade to Python 3 and need to maximize stability to deal with bytes vs. str issues.

@mekarpeles mekarpeles added Lead: @jimchamp Issues overseen by Jim (Front-end Lead, BookNotes) [managed] Module: JavaScript Issues related to the JavaScript functionality. [managed] Lead: @cclauss Issues overseen by Chris (Python3 & Dev-ops lead 2019-2021) [managed] Python and removed Lead: @mekarpeles Issues overseen by Mek (Staff: Program Lead) [managed] hacktoberfest Issues appropriate for Hacktoberfest participants Lead: @jimchamp Issues overseen by Jim (Front-end Lead, BookNotes) [managed] Module: JavaScript Issues related to the JavaScript functionality. [managed] labels Jan 25, 2021
@mekarpeles mekarpeles changed the title Remove unused imports from files. Investigate Python Unused Imports Jan 25, 2021
@mekarpeles mekarpeles added the Type: Epic A feature or refactor that is big enough to require subissues. [managed] label Jan 25, 2021
@Atheriz-46
Copy link

Hey, is this issue still open?? I can take it up.

@cclauss
Copy link
Contributor

cclauss commented Jan 26, 2021

It is still open but as mentioned above, we have a fair number of imports that have side-effects. This means that flake8 F401 might say that an import is not needed but removing it will create a crash/bug/etc. We are super-close to removing Python 2 and once that is done, we can go full force on this issue.

If you want to dig in now, just modify a single file per pull request. If PRs land cleanly, that is great. If they do not land cleanly, we can add comments that describe the side effects. Thanks for your interest!

@Enigma04
Copy link

if this issue is still open I would like to take it up

@cclauss
Copy link
Contributor

cclauss commented Feb 23, 2021

The issue is open but we have not removed the Python 2 code so let's hold off on attacking this one a little bit longer.

@vatsal-cmd
Copy link

I want to be a participant in solving this issue, i am a beginner can anyone tell me from where to start and till now what is the progress for this issue?

@cclauss
Copy link
Contributor

cclauss commented Feb 27, 2021

let's hold off on attacking this one a little bit longer.

@soham4abc
Copy link
Contributor

Can anyone please have a look at my PR It has been open for a while with no reviews! @cclauss @cdrini

@ItsApex
Copy link

ItsApex commented Dec 3, 2021

Hey @cclauss Is this issue still open I would like to contribute

@Eds-Dbug
Copy link
Contributor

@cclauss, I would like to be next in line to take up this issue.

@cclauss
Copy link
Contributor

cclauss commented Dec 22, 2022

The comments above still apply:

It is still open but as mentioned above, we have a fair number of imports that have side effects. This means that #3483 (comment) might say that an import is not needed but removing it will create a crash/bug/etc. If you want to dig in, modify one or two files per pull request. If PRs land cleanly, that is great. If they do not land cleanly, we can add comments that describe the side effects. Thanks for your interest!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue Easy issue. Good for newcomers. [managed] Lead: @cclauss Issues overseen by Chris (Python3 & Dev-ops lead 2019-2021) [managed] Priority: 3 Issues that we can consider at our leisure. [managed] python Pull requests that update Python code Type: Epic A feature or refactor that is big enough to require subissues. [managed] Type: Refactor/Clean-up Issues related to reorganization/clean-up of data or code (e.g. for maintainability). [managed]
Projects
None yet