Skip to content
Open
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
16 changes: 4 additions & 12 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1367,36 +1367,28 @@ def visit_Raise(self, n: ast3.Raise) -> RaiseStmt:

# Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
def visit_Try(self, n: ast3.Try) -> TryStmt:
body = self.as_required_block(n.body)
vs = [
self.set_line(NameExpr(h.name), h) if h.name is not None else None for h in n.handlers
]
types = [self.visit(h.type) for h in n.handlers]
handlers = [self.as_required_block(h.body) for h in n.handlers]

node = TryStmt(
self.as_required_block(n.body),
vs,
types,
handlers,
self.as_block(n.orelse),
self.as_block(n.finalbody),
body, vs, types, handlers, self.as_block(n.orelse), self.as_block(n.finalbody)
)
return self.set_line(node, n)

def visit_TryStar(self, n: TryStar) -> TryStmt:
body = self.as_required_block(n.body)
vs = [
self.set_line(NameExpr(h.name), h) if h.name is not None else None for h in n.handlers
]
types = [self.visit(h.type) for h in n.handlers]
handlers = [self.as_required_block(h.body) for h in n.handlers]

node = TryStmt(
self.as_required_block(n.body),
vs,
types,
handlers,
self.as_block(n.orelse),
self.as_block(n.finalbody),
body, vs, types, handlers, self.as_block(n.orelse), self.as_block(n.finalbody)
)
node.is_star = True
return self.set_line(node, n)
Expand Down
18 changes: 18 additions & 0 deletions test-data/unit/check-modules.test
Original file line number Diff line number Diff line change
Expand Up @@ -3239,6 +3239,24 @@ import b # type: ignore[import-not-found]
tmp/a.py:1: error: Unused "type: ignore" comment
[out2]

[case testRepeatedMissingImportKeepsFirstUnsuppressedError]
try:
import someweirdpackage
except:
import someweirdpackage # type: ignore[import-not-found]
[out]
main:2: error: Cannot find implementation or library stub for module named "someweirdpackage"
main:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

[case testRepeatedMissingImportKeepsFirstUnsuppressedError_old_parser]
try:
import someweirdpackage
except:
import someweirdpackage # type: ignore[import-not-found]
[out]
main:2: error: Cannot find implementation or library stub for module named "someweirdpackage"
main:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

[case testImportErrorStaleLoadedFromCacheIncremental]
import a
[file a.py]
Expand Down
Loading