[Python-ideas] warn/error when using a method as boolean in ifs/whiles
Nick Coghlan
ncoghlan at gmail.com
Tue Oct 11 12:35:19 EDT 2016
On 11 October 2016 at 23:59, Paul Moore <p.f.moore at gmail.com> wrote:
> Certainly. But the whole point of the warning is to catch people who
> do the wrong thing. All I'm saying is that the new warning would cause
> problems for people who omit a (currently unnecessary) "is None" check
> in the process of protecting people who forget whether an attribute is
> a method or a property. Which group do we prefer to help?
I don't think there's a technicality here: new warnings on valid code
count as a backwards compatibility break, as some folks run their test
suites under "-Werror". That means existing correct code wins by
default.
However, writing a "@predicatemethod" descriptor that folks could use
if they wanted to warn about that particular case may make sense.
That's already possible for API designers that choose to do it, so I
don't see a strong reason to add it to the standard library at this
point. (Especially since type inference engines are often going to be
able to pick this particular problem up statically)
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list