Skip to content

Conversation

@solaluset
Copy link

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 ensures end will never be out of range. With this fix applied, pytest properly shows that the error is TypeError: _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?

Copy link
Member

@nicoddemus nicoddemus left a 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?

@solaluset
Copy link
Author

Thank you for your reply. I thought about that, but not sure what would be a minimal reproducible example. I'll look into it.

@solaluset
Copy link
Author

Uh, pre commit messed it up

@solaluset
Copy link
Author

This is the reason why first line of function must start with non-space or be empty

# If we start with an indented line, put blockfinder to "started" mode.
block_finder.started = (
bool(source.lines[start]) and source.lines[start][0].isspace()
)

Otherwise end gets corrected and doesn't raise IndexError.
This is so tricky, I'm not sure if my solution is optimal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants