Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stubgen: Preserve empty tuple annotation #16907

Merged
merged 1 commit into from
Feb 11, 2024
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
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[()]): ...
Loading