-
Notifications
You must be signed in to change notification settings - Fork 64
Variadic positional args? #136
Comments
Yes, Oscar Benjamin's use case is interesting and worth keeping in mind when designing the general I actually tried to reply to his post, but his latest post indicates that, for whatever reason, he is completely ignoring it and holds on to this misconception of To give a brief summary of my answer for the initiated: the sympy objects he is referring to have a 'sequential structure' similar to tuples, but with an additional class/type. This is somewhat hidden at first as all the data is stored in a single attribute. The actual structure of an object is correctly represented by the pattern This could be implemented either through support of the sequence protocol, i.e. In his first post, Oscar Benjamin also mentioned that performance is critical for his intended use case of pattern matching. I therefore believe that any funny tweaks and trickery along the lines of having |
Also, given the large number of discrete types he is talking about, using a match statement is probably going to perform poorly, since we don't generate a dispatch table. |
Maybe part of that is a misconception, but IMO his argument from an ergonomics POV makes sense: even with just two levels of nesting, writing
is rather ugly compared to the ideal
and even the form with doubled parentheses is fairly ugly:
I'm not sure that follows. I doubt that he's proposing to write match statements with hundreds of cases. |
Oh, I just re-read his post and noticed this:
That does sound like it might not be easy to improve upon. Although he immediately continues
|
Oh, don't get me wrong: I think it is highly valid point he has brought up and something we certainly have to consider in the long run. I much rather have my doubts concerning the proposed solution, or even the location of the actual problem. Even though we more or less started with that idea, I think that closely reflecting the constructor arguments in the patterns is something of a dead end that does not move us much forward. Sure, this works with algebraic data types in functional languages, but objects in Python are quite a different beast. Hence, I do not really see much merit in the idea of including a starred version in I understand the idea behind it in that Starting from the tuple idea, we could also say that In the end, the most sensible course of action IMHO is to take this example as a corner stone for the future design of
|
Oscar Benjamin is proposing to allow
*rest
in class patterns, together with some way in__match_args__
to indicate this is allowed.See https://mail.python.org/archives/list/python-dev@python.org/thread/V6UC7QEG4WLQY6JBC4MEIK5UGF7X2GSD/
I personally don't think it's urgent to add this to the current PEP but it's an interesting thing to keep in mind for the future (probably together with the
__match__
proposal when we eventually get to it.)The text was updated successfully, but these errors were encountered: