Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/unimport/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ def match_2(self, imp: Import | ImportFrom) -> bool:
sub_match = (
not primary_match and imp.is_match_sub_packages(self.name) and not self._has_more_specific_import(imp)
)
is_match = (imp.lineno < self.lineno or self._is_deferred_usage(imp)) and (primary_match or sub_match)
is_match = (imp.lineno <= self.lineno or self._is_deferred_usage(imp)) and (primary_match or sub_match)
else:
is_match = (imp.lineno < self.lineno or self._is_deferred_usage(imp)) and (
is_match = (imp.lineno <= self.lineno or self._is_deferred_usage(imp)) and (
self.name == imp.name or imp.is_match_sub_packages(self.name)
)

Expand Down
21 changes: 21 additions & 0 deletions tests/cases/analyzer/statement/semicolon_same_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from typing import Union

from unimport.statement import Import, ImportFrom, Name

__all__ = ["NAMES", "IMPORTS", "UNUSED_IMPORTS"]


NAMES: list[Name] = [
Name(lineno=1, name="print", is_all=False),
Name(lineno=1, name="pathlib.Path", is_all=False),
Name(lineno=1, name="__file__", is_all=False),
Name(lineno=2, name="sys.exit", is_all=False),
Name(lineno=2, name="doctest.testmod", is_all=False),
Name(lineno=2, name="doctest.ELLIPSIS", is_all=False),
]
IMPORTS: list[Union[Import, ImportFrom]] = [
Import(lineno=1, column=1, name="pathlib", package="pathlib"),
Import(lineno=2, column=1, name="doctest", package="doctest"),
Import(lineno=2, column=2, name="sys", package="sys"),
]
UNUSED_IMPORTS: list[Union[Import, ImportFrom]] = []
2 changes: 2 additions & 0 deletions tests/cases/refactor/statement/semicolon_same_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
if True: import pathlib; print(pathlib.Path(__file__))
if True: import doctest, sys; sys.exit(doctest.testmod(optionflags=doctest.ELLIPSIS)[0])
2 changes: 2 additions & 0 deletions tests/cases/source/statement/semicolon_same_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
if True: import pathlib; print(pathlib.Path(__file__))
if True: import doctest, sys; sys.exit(doctest.testmod(optionflags=doctest.ELLIPSIS)[0])