Skip to content

Try to detect non-global unused imports.#369

Merged
Carreau merged 1 commit intodeshaw:masterfrom
Carreau:import-track
Nov 11, 2024
Merged

Try to detect non-global unused imports.#369
Carreau merged 1 commit intodeshaw:masterfrom
Carreau:import-track

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
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)
@Carreau Carreau changed the title Try to detect non-gloabl unused imports. Try to detect non-global unused imports. Jan 8, 2025
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