-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
PEP 590: kwnames should be non-empty tuple (or NULL) #1049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This has been argued in here and (since I seem to have gotten the threads confused) here. The Robustness principle for designing interfaces has been brought up. To our case, I believe it applies like this:
Both are good advice, but neither says much about the protocol. That means that (partially quoting the earlier discussion) the check for empty args will not be the simple:
but rather:
This is slightly more complicated, but not slower as the additional check is only required during error handling. Please reopen if you think it needs to be discussed further. |
I don't think that the argument of speed really matters (checking whether a tuple is empty is very fast, my motivations were more about simplicity and robustness than speed), but since you brought it up: it's not that the condition is only used during error handling. It's used during error checking, also in the non-error case. If an empty tuple becomes a valid way to indicate "no keyword arguments", you need to check that the tuple is empty if you don't want keyword arguments.
I already argued that we really should optimize for the callee here: the callee is often external code while the caller is almost certainly CPython (external code should use (I know I'm repeating the same arguments here, but only to refute the same arguments that have been made before) |
Can we then at least write explicitly in the PEP that empty tuples are valid? |
Note: I don't actually have permissions to do that. Of course, if you decide to allow empty tuples, I can live with that, it's actually a tiny change in the implementation of PEP 590. I just want to know that this decision was made for the right reasons. In particular, your comment seems to indicate some kind of symmetry between the caller and callee. If you assume such symmetry, I agree that it's hard to decide what the best option is. But I do not agree with the assumption of symmetry: external code is far more likely to be callee rather than caller. |
Apologies, I thought the author had the power! Reopening for you.
Stefan's post linked from the PEP mentions that several tools might want to use vectorcall even on CPython versions that didn't support it. These tools will necessarily need to supply both callers and callees.
We're not optimizing for performance, but for, let's say, "developer experience". What is that?
Definitely! |
Are you trying to say that it's easier for a developer A to convince a reviewer B that the code written by A is correct? Basically, to avoid the following scenario, assuming that empty tuples are forbidden: A. writes code of the form |
No, I mean the following scenario when implementing the caller: A. writes a caller that transforms kwargs to tuples, including empty kwargs to empty tuples |
OK, I see what you mean now but I think that your scenario is unlikely mainly because "implementing the caller" is unlikely. But maybe we should stop discussing and "agree to disagree". I would give @scoder a chance to reply in case he has a strong opinion. In any case, this is a detail and won't make a big difference for the PEP 590 implementation. |
The benefit of the conversation was clarifying intended use cases, rather than actually bikeshedding on this detail. I think we now both understand the other's point of view. Let's reopen if there is some new argument to be heard. |
If reopened, we should also look at the the CALL_FUNCTION_KW opcode: https://bugs.python.org/issue36936 & python/cpython#13357 |
Reopened what? I don't understand what you're trying to say here. |
Sorry! That was a bad typo. I meant "If reopened". |
Bad typo indeed. I couldn't guess that you meant that :-) |
For simplifying the code of the vectorcall callee, do not allow an empty tuple to be passed as
kwnames
. This way, there is a unique way to specify "no keyword arguments", namely passing aNULL
pointer.CC @encukou @markshannon @scoder