question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

B901 should not apply to __await__ methods

See original GitHub issue

Custom awaitable objects need to implement __await__ generator methods with a return to provide values. B901 triggers on these for Python2 compatibility, but it is very unlikely that Python2 would use an __await__ method. The __await__ method must be an iterator, so using async def as suggested by B901 is not valid.

Marking every occurrence as # noqa: B901 is very annoying in an async library. Disabling it entirely is suboptimal, because a generator-return outside of __await__ usually hints at an error indeed.

    def __await__(self) -> Generator[Any, Any, ST]:
        return (yield from self._await_message().__await__())

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
untitakercommented, Jun 30, 2019

Ah, I understand. Will fix.

0reactions
untitakercommented, Jun 30, 2019

I suppose that’s why return x in a generator function behaves the way it does. TIL! When I got around to this behavior in other contexts it made no sense at all, but here it does.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Should async method always call await, if not what is the ...
It seems that when the condition check is deferred, there is always a task being awaited, but when it's false in the handler,...
Read more >
Async/Await - Best Practices in Asynchronous Programming
I'll explain the reasoning behind each guideline so that it's clear when it does and does not apply. The guidelines are summarized in...
Read more >
flake8-bugbear - PyPI
A plugin for flake8 finding likely bugs and design problems in your program. Contains warnings that don't belong in pyflakes and pycodestyle.
Read more >
Understanding Control Flow with Async and Await in C# ...
The await keyword does not block the current thread. What do we mean by that? Let's look at some examples of blocking code....
Read more >
Async, Await, and ConfigureAwait – Oh My! | Core BTS Blog
To avoid this issue, you can use a method called ConfigureAwait with a false parameter. When you do, this tells the Task that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found