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
[MRG+1][Py3] Check for 'return' with arguments inside generators #3869
[MRG+1][Py3] Check for 'return' with arguments inside generators #3869
Conversation
Right, before Python 3.3 |
Codecov Report
@@ Coverage Diff @@
## master #3869 +/- ##
==========================================
- Coverage 85.56% 82.74% -2.82%
==========================================
Files 164 164
Lines 9551 9575 +24
Branches 1431 1436 +5
==========================================
- Hits 8172 7923 -249
- Misses 1132 1393 +261
- Partials 247 259 +12
|
Codecov Report
@@ Coverage Diff @@
## master #3869 +/- ##
==========================================
- Coverage 83.85% 83.73% -0.13%
==========================================
Files 165 165
Lines 9615 9656 +41
Branches 1440 1445 +5
==========================================
+ Hits 8063 8085 +22
- Misses 1304 1323 +19
Partials 248 248
|
tests/test_utils_misc/test_return_with_argument_inside_generator.py
Outdated
Show resolved
Hide resolved
I should also write a note about this on the docs. |
8951334
to
8ed9e80
Compare
In some tests I modified this line from Command:
There doesn't seem to be a noticeable impact on performance. If I'm not mistaken there is only one callback in this spider, and the function call is cached now, so the results might be partial. |
Travis failure is due to the fact that I removed the py2 compatibility, I can revert that commit at any time if there is in fact going to be a 1.8 release. |
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.
Have you considered the scenarios where the passed callback is a module-level function or a lambda? They may be worth covering in the tests.
I also wonder if caching affects lambda functions. I assume two identical lambda functions are still considered different objects, but I’m not sure.
I may need to start drinking coffee.
Taking https://stackoverflow.com/questions/11815873/memoization-library-for-python-2-7 into account, and since adding a new Python 2-specific dependency for this at this point may not be wise, it may still make sense to make your changes only work on Python 3, using a |
8ed9e80
to
9ae6414
Compare
af5f186
to
8d6c2ec
Compare
0f672d0
to
426b93e
Compare
6fd99fe
to
451e7a6
Compare
Thanks @elacuesta! As usual, thanks @Gallaecio for the review :) |
This triggers an issue when writing spiders in hy-lang Was pep 484#annotating-generator-functions-and-coroutines considered when solving this? I know my hy-lang scenario is extreme |
I don’t think we considered annotations as a solution here, but I am not sure they are a good fit because the point was to log something at run time without requiring users to run a static analysis tool separately. |
Fixes #3484
I also considered a version using
ast.NodeVisitor
, I think thewalk
-based solution should be more efficient since it can stop the iteration if the conditions are satisfied, while theNodeVisitor
class would visit allReturn
nodes.I plan on doing some benchmarking to determine if this has a noticeable performance impact, but I look forward to reading your feedback.