| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
@hauntsaninja This is related to #13686, this time for Iterable though. I think there is value in having a separate error code for it. Whether it should be enabled by default is a different question. Just for Home Assistant I'm going to adjust the typing for all but one instance. In practice none of them is a true issue though, just a possible one mypy wouldn't have noticed. |
Sorry, something went wrong.
|
Pushed a new commit to disable the error-code by default. That should minimize the impact of the PR. |
Sorry, something went wrong.
|
@JelleZijlstra Would you mind taking a look? The actual code change is quite small but I think it will be an improvement never the less. The PR is ready from my POV. |
Sorry, something went wrong.
| "Function {} could always be true in boolean context", code=codes.TRUTHY_FUNCTION | ||
| ) | ||
| ITERABLE_ALWAYS_TRUE: Final = ErrorMessage( | ||
| "{} which can always be true in boolean context. Consider using {} instead.", |
There was a problem hiding this comment.
This message reads a bit weird to me but I guess it's consistent with the other ALWAYS_TRUE messages.
Sorry, something went wrong.
There was a problem hiding this comment.
On its own, I agree. It gets better once the variables are inserted. E.g.
"var" has type "Iterable[str]" which can always be true in boolean context. Consider using "Collection[str]" instead. [truthy-iterable]
Sorry, something went wrong.
| This is similar in concept to ensuring that an expression's type implements an expected interface (e.g. ``Sized``), | ||
| except that attempting to invoke an undefined method (e.g. ``__len__``) results in an error, | ||
| while attempting to evaluate an object in boolean context without a concrete implementation results in a truthy value. |
There was a problem hiding this comment.
I don't understand what this sentence is trying to say. What is "this" exactly?
Sorry, something went wrong.
There was a problem hiding this comment.
As best as I can tell, "this" refers to the check itself and the fact that it doesn't highlight a concrete issue but rather only a potential one.
Sorry, something went wrong.
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Add a separate error code for truthy-iterable.
Iterable does not implement __len__, so passing a Generator would always evaluate to true. Suggest Collection as alternative.
In most cases this isn't an issue as the function is often called with list anyway. However, the dedicated check can pinpoint subtle errors that might get unnoticed otherwise.