| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Documentation build overview3 files changed ± c-api/weakref.html ± library/weakref.html ± whatsnew/changelog.html |
Sorry, something went wrong.
…ation * Python functions weakref.ref() and weakref.proxy() now raise TypeError if the callback argument is not callable or None. * C functions PyWeakref_NewRef() and PyWeakref_NewProxy() now raise TypeError if the callback argument is not callable, None, or NULL.
|
test_traceback.test_recursion_error_during_traceback() does fail. The script calls ref(lambda: 0, []) whereas [] is not callable. |
Sorry, something went wrong.
|
@isidentical, do you remember the purpose of ref(lambda: 0, []) in that test (GH-27313)? It's effect was raising a TypeError after destruction the weak-referred object (lambda: 0). Since this is not associated with any Python code, source_line should be NULL. I replaced the callback with ord, calling which should have the same effect. |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM. I just have a suggestion for test_traceback.
Sorry, something went wrong.
| def f(): | ||
| ref(lambda: 0, []) | ||
| ref(lambda: 0, ord) | ||
| f() |
There was a problem hiding this comment.
The test expects that calling the callback raises an exception. Currently, it raises a TypeError since [] (list) is not callable. I suggest making the exception more explicit:
def callback(wr):
raise Exception("error")
def f():
ref(lambda: 0, callback)
f()Passing ord() is more surprising to me.
Sorry, something went wrong.
There was a problem hiding this comment.
If I correctly understand the purpose of this test, we cannot do this. This would insert a Python frame, this would give a non-NULL source_line. This is why the test used such indirect way of raising an exception.
I am not completely sure in my reconstruction, this is why I have not added an explaining comment, which would be helpful here.
Sorry, something went wrong.
There was a problem hiding this comment.
The test was added by commit c836231.
At first ref(lambda: 0, []) calls, display_source_line() returns rc=0, no exception set, source_line is not NULL. But when we are getting closer to the recursion limit, display_source_line() can fail with RecursionError on the call:
fob = _PyObject_CallMethod(io, &_Py_ID(TextIOWrapper),
"Os", binary, encoding);In this case, display_source_line() clears the exception, returns 0 and source_line is NULL. Calling ignore_source_errors() here just sets err=0 (no exception is set), but err is already equal to 0. So I don't understand well what we are testing here.
Sorry, something went wrong.
There was a problem hiding this comment.
I am not confident in my explanation, and adding incorrect comment may be worse than missing comment.
Sorry, something went wrong.
|
I'm fine with ref(lambda: 0, ord). Maybe just add a comment explaining the purpose of the test_traceback test. |
Sorry, something went wrong.
|
I added @tekknolagi as a co-author. Even if this PR wasn't technically based on #26273, he started in the right place, and it's not his fault that his PR didn't get enough attention at the time. |
Sorry, something went wrong.
…ation (pythonGH-151145) * Python functions weakref.ref() and weakref.proxy() now raise TypeError if the callback argument is not callable or None. * C functions PyWeakref_NewRef() and PyWeakref_NewProxy() now raise TypeError if the callback argument is not callable, None, or NULL. Co-authored-by: Maxwell Bernstein <emacs@fb.com>
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.