c2c-oerpscenario team mailing list archive
-
c2c-oerpscenario team
-
Mailing list archive
-
Message #29790
[Bug 814620] Re: "if not <variable>" instead of "if <variable> is None"
Every time I see:
def ...(... <var>=None ...):
if not <var>:
<var> = {} # or any other falsy mutable values like []
I see it as a bug, as you can't pass an empty mutable to the function
(if you are interested on what/if any mutation happens in the function).
It is also somewhat of a performance bug and a problem for reading code
because in lot of places might call the function with different types,
so while reading code you end up not knowing what is the correct api of
a function.
I will try to find some time to patch some of the cases I see and send a
pull request.
--
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:
Confirmed
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