python-formate / flake8-dunder-all

A Flake8 plugin and pre-commit hook which checks to ensure modules have defined '__all__'.
https://flake8-dunder-all.readthedocs.io/en/latest
MIT License
7 stars 2 forks source link

feat: handle `if TYPE_CHECKING` block. #65

Closed peterschutt closed 5 months ago

peterschutt commented 5 months ago

We are experiencing an issue where the __all__ declaration gets positioned between runtime and type checking imports. E.g.,

image

So I've slapped this together as a PoC.

The PR updates visitor so that the last_import is updated for import lines that occur within an if TYPE_CHECKING block.

I've not done any ast stuff before, so don't really know if what I've added here is a good way to go about it, also how far I should go with tests. Any advice appreciated.

peterschutt commented 5 months ago

Thanks @domdfcoding!