-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: handle if TYPE_CHECKING
block.
#65
feat: handle if TYPE_CHECKING
block.
#65
Conversation
@@ -162,7 +162,7 @@ def handle_import(self, node: Union[ast.Import, ast.ImportFrom]) -> None: | |||
if not node.col_offset and node.end_lineno > self.last_import: # type: ignore[union-attr] | |||
self.last_import = node.end_lineno # type: ignore[union-attr] | |||
else: | |||
if not node.col_offset and node.lineno > self.last_import: | |||
if node.lineno > self.last_import: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the offset condition b/c the type check imports are offset - I expected this might break a test or two but it didn't (at least not in my local runs - ci still running so I might have gone the early crow!).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really sure why the check was there. Perhaps I was being overly cautious.
Updates the `last_import` line num for import lines that occur within an `if TYPE_CHECKING` block.
e8193a8
to
16e715f
Compare
16e715f
to
73e4c49
Compare
Thanks @domdfcoding! |
We are experiencing an issue where the
__all__
declaration gets positioned between runtime and type checking imports. E.g.,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 anif 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.