Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
GH-94822: Respect metaclasses when caching class attributes #94863
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
GH-94822: Respect metaclasses when caching class attributes #94863
Changes from all commits
dbc624c
28d1093
3f1e5ce
4f84a5c
606d460
6864e95
03aa529
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Do you think we should just play safe and fail whenever we see a non-
type
type? (ie whenever there's a metaclass)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.
We have simple ways of checking for all known problematic cases (names present in the metaclass,
__getattribute__
defined, mutating metaclasses). I guess we could do that, but it sort of feels like overkill to me.I'm currently running the benchmarks and gathering stats for this branch, but I worry that disallowing all metaclasses would really hurt benchmarks like
sympy
which have tons of metaclasses. So I'd want to make sure we don't suffer any big regressions before disallowing them entirely.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.
Thanks for the quick work @brandtbucher
I don't know if this helps but if you want to time SymPy specifically then one way is:
That takes about half an hour to run on this computer.
Comparing different CPython versions in CI shows that 3.11.0b4 currently gives a speedup for some jobs and is neutral for others:
https://github.com/sympy/sympy/actions/runs/2662492934
If you look at for example the
test2
matrix then the timings from there are:The test2 job does roughly half of what
sympy.test()
does and can be reproduce directly withsympy.test(split='2/2')
. The 3.10 timing is shown in CI astest2-latest
separately from thetest2
matrix of different Python versions.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.
Thanks, I'll take a look.
Side note, I just realized that potentially removing support for any metaclasses here would probably (further) trash
enum
performance. :( So that's also something we want visibility into before going that route.