Hi Takuo Matsuoka.

Thank you for your interest in the idea of applying keyword unpack
argument assignments at the time of assignment.

Great magic code, you could implement this at the software level.
But again it's not useful unless it's syntactically supported.


Currently in Python even this syntax is a syntax error(cannot give type hint).

```
(
  a: int,
  b: int
) = (1, 2)
```

If this syntax improves in the future, I would like unpacking keywords
to be supported as well.

```
(
  a: int,
  b: int,
  **kwargs
) = **{"a": 1, "b": 2, "c": 3}
```

2021年9月2日(木) 23:01 Matsuoka Takuo <motogeom...@gmail.com>:
>
> Dear 笹原康央,
>
> This sounds interesting. The assignment could be done e.g., like
> this.
>
> ```python
> def assign(variables):
>     return f'''
> for _variable, _value in (lambda {variables}: locals())(
>         *_values, **_assignments
> ).items():
>     exec(f'{{_variable}} = _value')
>     '''
>
> def name_update(_namespace, /, *_values, **_assignments):
>     return _namespace.update(locals())
>
> name_update(globals(),
>             1, 2, *[3,4], **{"b":4}, c=4
>             )
> exec(assign(
>     "a, *args, b, **kwargs"
> ))
>
> def f():
>     name_update(locals(),
>         1, 2, *[3,4], **{"b":4}, c=4
>     )
>     exec(assign(
>         "a, *args, b, **kwargs"
>     ))
>     return locals()
>
> ```
> This is certainly much more writing than an assignment statement. (It
> works also with global and nonlocal variables. One should remove the
> side effects, which shouldn't be hard with a context manager for
> instance. The code is not for assignment to the variable "_variable",
> "_value", or "exec". I haven't thought how to make assignment to any
> variable possible. Finally, the necessity to call exec requires care.)
>
> Best regards,
> Takuo Matsuoka
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/DP7VHA7GXPMXEMQ4TZKBA5GP73EEPNUB/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to