-
-
Notifications
You must be signed in to change notification settings - Fork 348
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
Fixes for 3.13 #3005
Fixes for 3.13 #3005
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3005 +/- ##
========================================
Coverage 99.63% 99.63%
========================================
Files 120 120
Lines 17783 17963 +180
Branches 3197 3243 +46
========================================
+ Hits 17718 17898 +180
Misses 46 46
Partials 19 19
|
# deep magic to remove refs via f_locals | ||
locals() | ||
# TODO: check if PEP558 changes the need for this call | ||
# https://github.com/python/cpython/pull/3640 |
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.
Back when we were making reference cycle tests, calling locals()
when an exception was around would make a reference cycle for every exception (i.e. every Cancelled
) unless you did both del and removed it from the f_locals
dict. if the test is passing on all versions without it, though, no reason to keep it around
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.
The test_cancel_scope_exit_doesnt_create_cyclic_garbage test fails on Fedora with Python 3.12 but passes with 3.13 :/
(However, we are stuck at 0.23.1, we are backporting this on top.)
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.
Perhaps something like:
if sys.version_info < (3, 13):
locals()
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.
Replacing locals()
with sys._getframe().f_locals
also does the trick for both Python 3.12 and Python 3.13. The code is too magical for me to tell whether it's factually correct.
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.
Just to confirm: latest state of the PR fails tests on fedora with Python 3.12? (That's not a platform in CI so very possible)
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.
I'm a bit confused cause when I used Python 3.12.3 on Fedora (Docker, I built CPython 3.12.3 from source) and pytest --pyargs trio --skip-optional-imports
on this PR, the tests pass. Am I missing something?
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.
As said, we are stuck at 0.23.1, we are backporting this PR on top of it, so perhaps that makes a difference.
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.
As said, we are stuck at 0.23.1, we are backporting this PR on top of it, so perhaps that makes a difference.
what's the reason you're stuck at 0.23.1? Looking at the changelog of 0.23.2 doesn't look like it should be introducing anything controversial.
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.
python-trio/trio-websocket#187 and possibly others
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.
that should only be affected from 0.25.0 though. If you're at the point where you're cherrypicking commits you could instead revert cfc0755
new f_locals method doesn't create a cycle in this situation
Seems like with these changes |
I think this is ready for review/merge. While this applied as a patch doesn't seem to work, I can't seem to reproduce that and I'm sure it's just some other PR that changed things just enough for this subtle locals stuff to work (which can be located probably just using a |
I think you can get 3.13 to pass in CI if you explicitly install I wrote a PR to get trio-websocket to support trio>0.25 python-trio/trio-websocket#188, so once merged that may fully resolve the issues encountered by the distro maintainers. |
Alright, this is now running the whole test suite (rather than the part that doesn't require the test requirements). |
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.
Makes sense, looks good as long as others are in agreement that the locals magic thing discussion is taken care of.
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.
I also don't understand locals()
magic, but the tests are passing and the other changes looks good.
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.
The locals()/garbage interaction isn't triggering some of the tests the way it was when I inserted it. I don't think it's worth bisecting python/trio to understand it or preemptively fixing, since it will be at worst a performance regression. If someone eventually stumbles on a reproducible regression to add to the tests, we know where to look for the fix.
Fixes #3004, also refs #2885
@njsmith could you check my naive
locals()
->sys._getframe().f_locals
replacement? Unfortunately 3.13 makeslocals()
mutations not mutate actual local variables, as part of PEP 667. I'm especially not sure about the replacement in_run.py
wherelocals()
used to clear something (not sure what).