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

Try to detect non-gloabl unused imports. #369

Merged
merged 1 commit into from
Nov 11, 2024

Conversation

Carreau
Copy link
Collaborator

@Carreau Carreau commented Nov 11, 2024

We do so by tracking the imports on exist of each scopestack; and on exist, if there is an import that has not been checked; we mark it as unused.

This seem to have side effects as the SourceToSource transformer is aware it cannot remove non-global imports and emit a error message.

Note that this also affects conditional imports:

if sys.version_info > X,y:
    from foo import bar
else:
    from foo.new import bar

The first import will be marked as unused as shoadowed by the second one (pyflyby does not understand the if/else).

This also does some refactor and type anotations while I am at it.

@Carreau Carreau force-pushed the import-track branch 3 times, most recently from 3d54464 to b5e38dc Compare November 11, 2024 10:49
We do so by tracking the imports on exist of each scopestack; and on
exist, if there is an import that has not been checked; we mark it as
unused.

This seem to have side effects as the SourceToSource transformer is
aware it cannot remove non-global imports and emit a error message.

Note that this also affects conditional imports:

```
if sys.version_info > X,y:
    from foo import bar
else:
    from foo.new import bar
```

The first import will be marked as unused as shoadowed by the second one
(pyflyby does not understand the if/else).

This also does some refactor and type anotations while I am at it.
@Carreau
Copy link
Collaborator Author

Carreau commented Nov 11, 2024

Partial step toward #273

@Carreau Carreau merged commit 626a7e3 into deshaw:master Nov 11, 2024
7 checks passed
saharan-deshaw pushed a commit that referenced this pull request Dec 3, 2024
Major changes:

- Bumped lint from 3.12 to 3.13 (#370)
- Bumped actions/checkout from 3 to 4 (#371)
- Bumped peaceiris/actions-gh-pages from 3 to 4 (#373)
- Bumped codecov/codecov-action from 2 to 4 (#374)
- Bump actions/setup-python from 3 to 5 (#372)
- Try to detect non-gloabl unused imports (#369)
- Set sys.last_value / sys.last_exc before entering the debugger (#380)
- Disable auto-import of lazy variables (#379)
- Bump codecov/codecov-action from 4 to 5 (#378)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant