Re: Python-Dev Digest, Vol 204, Issue 129
On 25 Jul 2020, at 03:44, Rob Cliffe <rob.cliffe@btinternet.com> wrote:
Without arguing for or against allowing a capture variable, IMO rather than syntax like match <expr> into <var>: it would be far better (and not require a new keyword) to write this as with <var> as match <expr>:
On 24/06/2020 20:38, Guido van Rossum wrote:
Everyone,
If you've commented and you're worried you haven't been heard, please=20 add your issue *concisely* to this new thread. Note that the following=20 issues are already open and will be responded to separately; please=20 don't bother commenting on these until we've done so:
- Alternative spellings for '|' - Whether to add an 'else' clause (and how to indent it) - A different token for wildcards instead of '_' - What to do about the footgun of 'case foo' vs. 'case .foo'
(Note that the last two could be combined, e.g. '?foo' or 'foo?' to=20 mark a variable binding and '?' for a wildcard.)
We already have 'with' for contexts. We already have patterns with 'as': - except expression "as" identifier ":" - "import" module "as" identifier - "with" expression "as" target So I think this would be quite confusing.
On 24/06/2020 20:38, Guido van Rossum wrote:
Everyone,
If you've commented and you're worried you haven't been heard, please=20 add your issue *concisely* to this new thread. Note that the following=20 issues are already open and will be responded to separately; please=20 don't bother commenting on these until we've done so:
- Alternative spellings for '|' - Whether to add an 'else' clause (and how to indent it) - A different token for wildcards instead of '_' - What to do about the footgun of 'case foo' vs. 'case .foo'
(Note that the last two could be combined, e.g. '?foo' or 'foo?' to=20 mark a variable binding and '?' for a wildcard.)
Can we extend the syntax for the match statement from match_stmt: "match" expression ':' NEWLINE INDENT case_block+ DEDENT to match_stmt: "match" expression ['as' NAME] ':' NEWLINE INDENT case_block+ DEDENT with the same meaning as in "with"? So the variable with the NAME assumes the value of the expression. That way I won’t have to use the walrus at every case where I need the full result of the expression. It could even be used to get rid of the walrus_pattern entirely. Example: match nested_data[index].attribute as foo: ... case SomeClass(…): bar(foo) … case AnotherClass(…): baz(foo) …
On 24/06/2020 20:38, Guido van Rossum wrote:
Everyone,
If you've commented and you're worried you haven't been heard, please=20 add your issue *concisely* to this new thread. Note that the following=20 issues are already open and will be responded to separately; please=20 don't bother commenting on these until we've done so:
- Alternative spellings for '|' - Whether to add an 'else' clause (and how to indent it) - A different token for wildcards instead of '_' - What to do about the footgun of 'case foo' vs. 'case .foo'
(Note that the last two could be combined, e.g. '?foo' or 'foo?' to=20 mark a variable binding and '?' for a wildcard.)
Can we extend the syntax for the match statement from match_stmt: "match" expression ':' NEWLINE INDENT case_block+ DEDENT to match_stmt: "match" expression ['as' NAME] ':' NEWLINE INDENT case_block+ DEDENT with the same meaning as in "with"? So the variable with the NAME assumes the value of the expression. That way I won’t have to use the walrus at every case where I need the full result of the expression. It could even be used to get rid of the walrus_pattern entirely. Example: match nested_data[index].attribute as foo: ... case SomeClass(…): bar(foo) … case AnotherClass(…): baz(foo) …
participants (1)
-
Eric Nieuwland