mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
This PR adds parentheses to kwargs unpacking `func(*args, **(kwargs or {}))` for better code readability.
With/without the parentheses are semantic equivalent because they produce the same bytecode.
```console
$ echo "func(*args, **kwargs or {})" | python3 -m dis -
0 0 RESUME 0
1 2 PUSH_NULL
4 LOAD_NAME 0 (func)
6 LOAD_NAME 1 (args)
8 BUILD_MAP 0
10 LOAD_NAME 2 (kwargs)
12 JUMP_IF_TRUE_OR_POP 1 (to 16)
14 BUILD_MAP 0
>> 16 DICT_MERGE 1
18 CALL_FUNCTION_EX 1
20 POP_TOP
22 LOAD_CONST 0 (None)
24 RETURN_VALUE
$ echo "func(*args, **(kwargs or {}))" | python3 -m dis -
0 0 RESUME 0
1 2 PUSH_NULL
4 LOAD_NAME 0 (func)
6 LOAD_NAME 1 (args)
8 BUILD_MAP 0
10 LOAD_NAME 2 (kwargs)
12 JUMP_IF_TRUE_OR_POP 1 (to 16)
14 BUILD_MAP 0
>> 16 DICT_MERGE 1
18 CALL_FUNCTION_EX 1
20 POP_TOP
22 LOAD_CONST 0 (None)
24 RETURN_VALUE
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/115026
Approved by: https://github.com/Skylion007
|
||
|---|---|---|
| .. | ||
| amp_examples.rst | ||
| autograd.rst | ||
| broadcasting.rst | ||
| cpu_threading_runtimes.svg | ||
| cpu_threading_torchscript_inference.rst | ||
| cpu_threading_torchscript_inference.svg | ||
| cuda.rst | ||
| ddp.rst | ||
| extending.func.rst | ||
| extending.rst | ||
| faq.rst | ||
| gradcheck.rst | ||
| hip.rst | ||
| large_scale_deployments.rst | ||
| modules.rst | ||
| mps.rst | ||
| multiprocessing.rst | ||
| numerical_accuracy.rst | ||
| randomness.rst | ||
| serialization.rst | ||
| windows.rst | ||