B011 is misleading, and the advice doesn't sound good
See original GitHub issueB011 Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError().
There are two problems with this:
- Removal of assertions with
-Ois not limited toassert Falsecases, it removes all assertions. So the message is misleading. - The suggestion to replace this assert with
raise AssertionError()is not a good one, because such a construct cannot be disabled by disabling assertions when one explicitly wants to do that.
Given these considerations, I cannot think of a good use case or a fix for B011 in the first place, so I suggest removing it altogether.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Minikube start virtualbox hang on MacOS Big Sur · Issue #10011
I am trying to start minikube on MacOS. I have installed all needed software via homebrew. When I type minikube start I get...
Read more >LEIVI Electric Bidet Smart Toilet Seat with Dual Control Mode ...
It makes no noise and will not wake your family at night. You don't have to stoop to close the seat, which is...
Read more >Order: CFTC v. Barclays PLC, et al
Instead, Barclays conveyed false, misleading or knowingly inaccurate reports that its submitted rates for LIBOR and Euribor were based on and.
Read more >'Never Look Away' review: This German drama is one of the ...
The German drama, nominated for a cinematography Oscar, is based on the life of painter Gerhard Richter.
Read more >Comparing methods of category learning: Classification ...
In contrast, classification learning does not result in such a bias due to ... Analysis included standard parametric statistics as well as ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

assertdefinitely has its place, so warning for every occurrence seems misleading. The entire point of assertions is that they can be switched off. So one actually should use them similar to how @gaul describes it: Have some costly checks that can be disabled in production.However,
-Oimplies the assertion machinery is switched off. Entirely. That means two things:AssertionErrordefeats the purpose ofassertbeing optional. That means the suggestion of B011 encourages misuse of assertions.AssertionErrorleads to different-O-behaviour at a distance. It is a better indication of misusing assertions.A better replacement for
assert Falseisraise NotImplementedError, since it usually indicates a dead code path. However, I would rather suggest to flagexcept AssertionError, perhaps flagraise AssertionErroras well. They indicate that assertions are misused for control flow, which they are not suitable for.Came here to report basically the same problem. I see this is more controversial than I expected. Would it be acceptable to have an opinionated version of this warning (B911?) that would flag all assertions outside of tests functions and classes, assuming those are all named with
testas a case-insensitive prefix ?