-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix internal error when source is modified #13884
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
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 @solaluset!
Usually we request a test, specially to avoid possible regressions in the future. Can you think of a simple test case to add to the test suite with that intent?
|
Thank you for your reply. I thought about that, but not sure what would be a minimal reproducible example. I'll look into it. |
pytest should not crash when source is dynamically modified
for more information, see https://pre-commit.ci
|
Uh, pre commit messed it up |
|
This is the reason why first line of function must start with non-space or be empty pytest/src/_pytest/_code/source.py Lines 205 to 208 in 4253f98
Otherwise end gets corrected and doesn't raise IndexError.This is so tricky, I'm not sure if my solution is optimal. |
|
@nicoddemus do I need to do anything else? |
|
Hey @solaluset, thank you for the PR and the automated test. Shouldn't getstatementrange_ast be fixed at the source instead of special casing a first empty line elsewhere ? Also could you add a changelog, please ? |
|
Thanks for the response. I'm not sure I get your first point. Do you mean |
Hello. I develop a project that heavily depends on code modification and monkeypatching: https://github.com/solaluset/pwcp/tree/pytest-broken
In some cases when things get wrong (as replicated in pytest-broken branch), pytest terminates with a long traceback of
INTERNALERROR> IndexError: list index out of range. Change in this PR ensuresendwill never be out of range. With this fix applied, pytest properly shows that the error isTypeError: _maybe_compile() takes 3 positional arguments but 4 were given.This is probably a niche case, but extra out-of-bounds check won't hurt anyone, right?