[IMP] coding_guidelines: fix python code indents

A few python code blocks on the coding guidelines are indented twice
(8 spaces instead of 4), which is not correct.

closes odoo/documentation#3898

Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
Nicolas (vin) 2023-03-27 13:28:35 +00:00
parent 697cdad097
commit 16176fb508

View File

@ -493,19 +493,19 @@ Idiomatics of Programming (Python)
# a bit complex and with a redundant temp variable # a bit complex and with a redundant temp variable
def axes(self, axis): def axes(self, axis):
axes = [] axes = []
if type(axis) == type([]): if type(axis) == type([]):
axes.extend(axis) axes.extend(axis)
else: else:
axes.append(axis) axes.append(axis)
return axes return axes
# clearer # clearer
def axes(self, axis): def axes(self, axis):
if type(axis) == type([]): if type(axis) == type([]):
return list(axis) # clone the axis return list(axis) # clone the axis
else: else:
return [axis] # single-element list return [axis] # single-element list
- Know your builtins : You should at least have a basic understanding of all - Know your builtins : You should at least have a basic understanding of all
the Python builtins (http://docs.python.org/library/functions.html) the Python builtins (http://docs.python.org/library/functions.html)
@ -527,7 +527,7 @@ meaning, be sure that you're using the right one.
# not very good # not very good
cube = [] cube = []
for i in res: for i in res:
cube.append((i['id'],i['name'])) cube.append((i['id'],i['name']))
# better # better
cube = [(i['id'], i['name']) for i in res] cube = [(i['id'], i['name']) for i in res]
@ -551,13 +551,13 @@ So, you can write ``if some_collection:`` instead of ``if len(some_collection):`
# creates a temporary list and looks bar # creates a temporary list and looks bar
for key in my_dict.keys(): for key in my_dict.keys():
"do something..." "do something..."
# better # better
for key in my_dict: for key in my_dict:
"do something..." "do something..."
# accessing the key,value pair # accessing the key,value pair
for key, value in my_dict.items(): for key, value in my_dict.items():
"do something..." "do something..."
- Use dict.setdefault - Use dict.setdefault