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
5 changes: 5 additions & 0 deletions mypy/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,11 @@ def _get_func_args(self, o: FuncDef, ctx: FunctionContext) -> list[ArgSig]:
new_args = infer_method_arg_types(
ctx.name, ctx.class_info.self_var, [arg.name for arg in args]
)

if ctx.name == "__exit__":
self.import_tracker.add_import("types")
self.import_tracker.require_name("types")

if new_args is not None:
args = new_args

Expand Down
2 changes: 2 additions & 0 deletions test-data/unit/stubgen.test
Original file line number Diff line number Diff line change
Expand Up @@ -3777,6 +3777,8 @@ class MatchNames:
def __exit__(self, type, value, traceback): ...

[out]
import types

class MismatchNames:
def __exit__(self, tp: type[BaseException] | None, val: BaseException | None, tb: types.TracebackType | None) -> None: ...

Expand Down