Skip to content

Commit e40d3fa

Browse files
committed
Remove unused aliased imports
1 parent 174bb58 commit e40d3fa

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

pyimport.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ on line number LINE, remove VAR (e.g. 'baz')."
247247
(pyimport--remove-on-line var))
248248
;; If we only have "from foo import " left, remove the rest of the line.
249249
(when (or (looking-at (rx "from " (1+ (not (any space))) " import" (1+ space) line-end))
250+
(looking-at (rx "from " (1+ (not (any space))) " import " (1+ (not (any space))) " as" (1+ space) line-end))
250251
(looking-at (rx "import " (1+ (not (any space))) " as" (1+ space) line-end)))
251252
(pyimport--delete-current-line)))))))
252253

test/pyimport-test.el

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
(should
3333
(equal (buffer-string) ""))))
3434

35+
(ert-deftest remove-import-as ()
36+
"Ensure we remove imports correctly when there are aliases."
37+
(with-temp-buffer
38+
(insert "from foo import bar as newname")
39+
(pyimport--remove-import 1 "newname")
40+
(should
41+
(equal (buffer-string) ""))))
42+
3543
(ert-deftest remove-on-line-first ()
3644
"We should remove the first occurrence, if present."
3745
(with-temp-buffer

0 commit comments

Comments
 (0)