Skip to content

Commit b6e91d4

Browse files
authored
stubgen: Preserve empty tuple annotation (#16907)
1 parent 4a9c1e9 commit b6e91d4

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

mypy/stubutil.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ def visit_unbound_type(self, t: UnboundType) -> str:
250250
self.stubgen.import_tracker.require_name(s)
251251
if t.args:
252252
s += f"[{self.args_str(t.args)}]"
253+
elif t.empty_tuple_index:
254+
s += "[()]"
253255
return s
254256

255257
def visit_none_type(self, t: NoneType) -> str:

test-data/unit/stubgen.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4253,3 +4253,17 @@ def f5(x: int, /, *, y: float): ...
42534253
def f6(x: int = 0, /, *, y: float): ...
42544254
def f7(x: int, /, *, y: float = 1): ...
42554255
def f8(x: int = 0, /, *, y: float = 1): ...
4256+
4257+
[case testPreserveEmptyTuple]
4258+
ann: tuple[()]
4259+
alias = tuple[()]
4260+
def f(x: tuple[()]): ...
4261+
class C(tuple[()]): ...
4262+
4263+
[out]
4264+
ann: tuple[()]
4265+
alias = tuple[()]
4266+
4267+
def f(x: tuple[()]): ...
4268+
4269+
class C(tuple[()]): ...

0 commit comments

Comments
 (0)