-
Notifications
You must be signed in to change notification settings - Fork 8
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
Fix error when using multiline lambdas in until
method
#52
base: master
Are you sure you want to change the base?
Conversation
@ppopov212 Thanks for the PR, can you also add a test for this new functionality? |
Sure, I'll add one |
@rockem I've added a test, I hope it's ok 🤞 |
@rockem I've made changes, you can check them 🙏 |
@@ -40,5 +41,12 @@ def test_lambda_content_with_captures(): | |||
assert 'x == y' == e.value.description | |||
|
|||
|
|||
def test_multi_line_lambda_content_description(): |
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.
Very nice!
@@ -28,5 +28,7 @@ def _is_a_lambda(func: Callable) -> bool: | |||
|
|||
def _content_of(lambda_func: Callable) -> str: | |||
source_line = inspect.getsource(lambda_func) | |||
source_line = re.sub(r'\\', '', source_line) |
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 problem with this solution is that it will work on strings and comments
So in order to resolve it we need something more sophisticated.
So, I think we can live with it in the description for now, and keep this PR simple
wdyt?
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 know multi-line lambdas in Python sounds strange, but hear me out. In a project of mine, I use Black for code formatting, and Black sometimes can format l long lambdas like this
So in this case busypie fails with the following message
AttributeError: 'NoneType' object has no attribute 'group'
After some digging, I found that busypie inspects the lambda function and runs a regex on the source. In this case, the regex is failing to match. I'm talking about this function in
func.py
fileMy naive solution for a fix is to replace one or more whitespace characters with a single whitespace character. This removes the new lines and the regex is matching now. I've run the tests and they all pass