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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix magic method yields (__next__, __anext__, __aiter__) #2400
Fix magic method yields (__next__, __anext__, __aiter__) #2400
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!
We totally need:
- A
CHANGELOG
entry for this - A test case for this, since it is rather complex
oop.AsyncMagicMethodViolation(node, text=node.name), | ||
) | ||
can_async = node.name in constants.ASYNC_IF_YIELDS_MAGIC_METHODS | ||
if not (can_async and walk.is_contained(node, (ast.Yield))): |
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.
if not (can_async and walk.is_contained(node, (ast.Yield))): | |
if not (can_async and walk.is_contained(node, ast.Yield)): |
I'll work on figuring out how to do the tests and hopefully have something by the end of the week. |
|
__anext__: This is a runtime constraint. __anext__ cannot be a generator. This will cause the runtime to throw a TypeError when used in an async for loop. __next__: The usefulness of having __next__ be a generator is practically nil. Doing so will cause an infinite loop with a new generator object passed to each iteration.
__aiter__ can only contain yield if it is an async function (async generator). Otherwise it must be a sync function that does not contain yield and returns an object that implements __anext__.
79168c1
to
6fbad72
Compare
Codecov Report
@@ Coverage Diff @@
## master #2400 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 119 119
Lines 6383 6390 +7
Branches 1446 1449 +3
=========================================
+ Hits 6383 6390 +7
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
I have made things!
Checklist
CHANGELOG.md
Related issues
Closes #2399
馃檹 Please, if you or your company is finding wemake-python-styleguide valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/wemake-python-styleguide. As a thank you, your profile/company logo will be added to our main README which receives hundreds of unique visitors per day.