c2c-oerpscenario team mailing list archive
-
c2c-oerpscenario team
-
Mailing list archive
-
Message #29151
Re: [Bug 814620] [NEW] "if not <variable>" instead of "if <variable> is None"
On Friday 22 July 2011, you wrote:
> Public bug reported:
>
> In a lot of places (I greped "if +not +\w+:" and found tons of these)
> the function definition says <variable>=None and then check if the
> variable is false then creates an empty var. In python empty vars are
> usually false, so if someones passes an empty var the function will
> create a new one, both creating more objects than it needs to and making
> it way harder to test openerp code. Changing it to if <variable> is None
> is both more semantically correct and will make the problem go away.
>
Well neither "not var" nor "var is None" can be a generally good solution for
all cases.
Sometimes we only want to test against the 'None' value, explicitly. Other
times we want to catch all negative values (such as False, [], {} and '').
I appreciate that there /might/ be places where the current "not var" test is
not the most politically correct.
But we can't just change all the instances blindly.
If you can indicate specific cases where the current test might be wrong, you
are welcome to help improve it.
--
You received this bug notification because you are a member of C2C
OERPScenario, which is subscribed to the OpenERP Project Group.
https://bugs.launchpad.net/bugs/814620
Title:
"if not <variable>" instead of "if <variable> is None"
Status in OpenERP Server:
New
Bug description:
In a lot of places (I greped "if +not +\w+:" and found tons of these)
the function definition says <variable>=None and then check if the
variable is false then creates an empty var. In python empty vars are
usually false, so if someones passes an empty var the function will
create a new one, both creating more objects than it needs to and
making it way harder to test openerp code. Changing it to if
<variable> is None is both more semantically correct and will make the
problem go away.
To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-server/+bug/814620/+subscriptions
References