-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
gh-138912: Improve MATCH_CLASS opcode performance #138915
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
base: main
Are you sure you want to change the base?
Conversation
Python/ceval.c
Outdated
if (seen == NULL) { | ||
return NULL; | ||
PyObject *seen = NULL; | ||
if (nattrs > 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (nattrs > 1) { | |
if (nargs > 1 || (nargs == 1 && nkwargs > 0)) { |
As mentioned in #138912, I'd also like to change this. If there are only keyword arguments, it's easy to see if two are the same name. Furthermore linters are able to detect these based on the AST alone.
It would also be great to say if we could suggest users to prefer keyword arguments. Not only are they more explicit, they are also faster. (No lookup of __match_args__
and, with the change, no expensive duplicate name detection.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this in f585253 with if (nargs > 0 && nattrs > 1)
. I can revert it if necessary.
_PyErr_Format(tstate, PyExc_TypeError, | ||
"%s() got multiple sub-patterns for attribute %R", | ||
((PyTypeObject*)type)->tp_name, name); | ||
if (seen != NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what do you need this change? Maybe I'm missing, but other changes don't require this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ough, I see. At least this needs a comment, IMHO.
Uh oh!
There was an error while loading. Please reload this page.