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

F401 false positive in try except ImportError #4790

Closed
Skylion007 opened this issue Jun 1, 2023 · 2 comments · Fixed by #4793
Closed

F401 false positive in try except ImportError #4790

Skylion007 opened this issue Jun 1, 2023 · 2 comments · Fixed by #4793
Assignees
Labels
bug Something isn't working

Comments

@Skylion007
Copy link
Contributor

F401 delete an import statement used to check whether a module is installed:
 try:
     import slack_sdk
     del slack_sdk
 except ImportError as e:
     raise MissingConditionalImportError('health_checker', 'slack_sdk', None) from e
Code snippet from https://github.com/mosaicml/composer
This auto fix just removed the import statement which creates an error when it is run again.
     try:
         del slack_sdk
     except ImportError as e:
         raise MissingConditionalImportError('health_checker', 'slack_sdk', None) from e

Obviously, the new code is a bad fix.

@charliermarsh
Copy link
Member

I thought we handled this case (try-catch with ImportError) explicitly. It’s supposed to flag, but not autofix.

@charliermarsh charliermarsh added the bug Something isn't working label Jun 1, 2023
@charliermarsh
Copy link
Member

Guessing it’s related to the del but I’ll have to test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants