Skip to content

Commit

Permalink
stubgen: Preserve empty tuple annotation (#16907)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamdanal committed Feb 11, 2024
1 parent 4a9c1e9 commit b6e91d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mypy/stubutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ def visit_unbound_type(self, t: UnboundType) -> str:
self.stubgen.import_tracker.require_name(s)
if t.args:
s += f"[{self.args_str(t.args)}]"
elif t.empty_tuple_index:
s += "[()]"
return s

def visit_none_type(self, t: NoneType) -> str:
Expand Down
14 changes: 14 additions & 0 deletions test-data/unit/stubgen.test
Original file line number Diff line number Diff line change
Expand Up @@ -4253,3 +4253,17 @@ def f5(x: int, /, *, y: float): ...
def f6(x: int = 0, /, *, y: float): ...
def f7(x: int, /, *, y: float = 1): ...
def f8(x: int = 0, /, *, y: float = 1): ...

[case testPreserveEmptyTuple]
ann: tuple[()]
alias = tuple[()]
def f(x: tuple[()]): ...
class C(tuple[()]): ...

[out]
ann: tuple[()]
alias = tuple[()]

def f(x: tuple[()]): ...

class C(tuple[()]): ...

0 comments on commit b6e91d4

Please sign in to comment.