Created
November 5, 2025 06:04
-
-
Save ichux/e1ff8fa2a6f2cb30d174476383a6b460 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| python3 << 'EOF' | |
| import ast | |
| import sys | |
| file_path = "~/test_clinical_study.py" | |
| with open(file_path, 'r') as f: | |
| tree = ast.parse(f.read(), filename=file_path) | |
| imported = set() | |
| used = set() | |
| for node in ast.walk(tree): | |
| if isinstance(node, ast.Import): | |
| for alias in node.names: | |
| name = alias.asname if alias.asname else alias.name | |
| imported.add(name.split('.')[0]) | |
| elif isinstance(node, ast.ImportFrom): | |
| for alias in node.names: | |
| name = alias.asname if alias.asname else alias.name | |
| imported.add(name) | |
| elif isinstance(node, ast.Name): | |
| used.add(node.id) | |
| elif isinstance(node, ast.Attribute): | |
| if isinstance(node.value, ast.Name): | |
| used.add(node.value.id) | |
| unused = imported - used | |
| if unused: | |
| print("Unused imports found:", sorted(unused)) | |
| else: | |
| print("No unused imports found") | |
| EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment