8000 stubgen: Preserve simple defaults in function signatures by hamdanal · Pull Request #15355 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

stubgen: Preserve simple defaults in function signatures #15355

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

Merged
merged 9 commits into from
Nov 27, 2023
Prev Previous commit
Next Next commit
Improve handling of {**something} case
  • Loading branch information
hamdanal committed Jun 27, 2023
commit 86242985448a84fe83876368c733088458741892
4 changes: 3 additions & 1 deletion mypy/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,9 @@ def get_str_default_of_node(self, rvalue: Expression) -> str:
elif isinstance(rvalue, DictExpr):
items_defaults = []
for k, v in rvalue.items:
k_default = self.get_str_default_of_node(k) if k is not None else "..."
if k is None:
break
k_default = self.get_str_default_of_node(k)
v_default = self.get_str_default_of_node(v)
if k_default == "..." or v_default == "...":
break
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/stubgen.test
Original file line number Diff line number Diff line change
Expand Up @@ -3356,11 +3356,11 @@ def j(x=[(1, 'a'), (2, 'b')]) -> None: ...
[case testDefaultsOfBuiltinContainersWithNonTrivialContent]
def f(x=(1, u.v), y=(k(),), z=(w,)): ...
def g(x=[1, u.v], y=[k()], z=[w]): ...
def h(x={1: u.v}, y={k(): 2}, z={w: w}): ...
def h(x={1: u.v}, y={k(): 2}, z={m: m}, w={**n}): ...
def i(x={u.v, 2}, y={3, k()}, z={w}): ...

[out]
def f(x=..., y=..., z=...) -> None: ...
def g(x=..., y=..., z=...) -> None: ...
def h(x=..., y=..., z=...) -> None: ...
def h(x=..., y=..., z=..., w=...) -> None: ...
def i(x=..., y=..., z=...) -> None: ...
0