dart-lang / dart-lang/language

Abbreviated formal parameter lists using kwargs

Open
#58 9 comments 17 reactions 0 assignees View on GitHub
feature state-backlog
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

In response to the topic filed as request #57, Mouad Debbar mentioned that Python supports a special formal parameter declaration `**kwargs`, which would make it possible to achieve the following much shorter form of the example from #57:

```dart
class Base {
final int foo;
final String bar;
final bool baz;
Base({this.foo, this.bar, this.baz});
}

class Sub1 extends Base {
final List myFoo;
Sub1({this.myFoo, **kwargs}): super({**kwargs});
}

class Sub2 extends Sub1 {
final Map myBar;
Sub2({this.myBar, **kwargs}): super({**kwargs});
}
```

Considered purely as syntactic sugar, it would be possible for the analyzer and compilers to expand `**kwards` into the actual list of named arguments, which would make it easy to proceed with the standard static analysis of both declarations and corresponding call sites using the rules we have today. It would then be possible to let `**kwargs` stand for a set of named formal parameter declarations on one side of the `:`, and passing those named parameters on to parameters with the same name on the other side.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.