You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An import like import module.submodule is removed when module.submodule is not used 1:1. However, we may use module.other_submodule or module.some_other_name in the file, which then becomes invalid and as such our codebase is broken.
The urllib.parse.urlparse(url) works here (somewhat surprisingly), because import urllib.request implicitly imports urllib, allowing us to access urllib.parse as well.
Running unimport against the file will detect import urllib.request as unused and remove it:
$ python my_module.py
Traceback (most recent call last):
File "my_module.py", line 7, in<module>
print(parse_url("http://google.com"))
File "my_module.py", line 4, in parse_url
return urllib.parse.urlparse(url)
NameError: name 'urllib' is not defined
Proposed Solution
unimport should be able to detect these cases and either prefer to not remove anything here or at least let us configure the behaviour to be more or less forgiving (maybe via --strict defaulting to True). I do see unimport as a cleanup mechanism to keep the codebase tidy, but it should never break anything, I'd much prefer to have a weird import lingering around if I had to choose.
Thank you for your time!
The text was updated successfully, but these errors were encountered:
Okay I am a bit confused since this seems to have been mentioned before in #127 and should have been fixed in v0.7.1, but I am still experiencing this on v0.8.3 right now.
Problem
An import like
import module.submodule
is removed whenmodule.submodule
is not used 1:1. However, we may usemodule.other_submodule
ormodule.some_other_name
in the file, which then becomes invalid and as such our codebase is broken.Example
The
urllib.parse.urlparse(url)
works here (somewhat surprisingly), becauseimport urllib.request
implicitly importsurllib
, allowing us to accessurllib.parse
as well.Running
unimport
against the file will detectimport urllib.request
as unused and remove it:As a result, the module is now broken:
Proposed Solution
unimport
should be able to detect these cases and either prefer to not remove anything here or at least let us configure the behaviour to be more or less forgiving (maybe via--strict
defaulting toTrue
). I do seeunimport
as a cleanup mechanism to keep the codebase tidy, but it should never break anything, I'd much prefer to have a weird import lingering around if I had to choose.Thank you for your time!
The text was updated successfully, but these errors were encountered: