From 460015160548fbc87b679ffe7eca7ac82b9796f7 Mon Sep 17 00:00:00 2001 From: "Nicolas (vin)" Date: Mon, 27 Mar 2023 13:28:35 +0000 Subject: [PATCH] [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#3906 X-original-commit: 16176fb50859140d6c43f0b48099402508cdc424 Signed-off-by: Victor Feyens (vfe) --- .../development/coding_guidelines.rst | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/content/contributing/development/coding_guidelines.rst b/content/contributing/development/coding_guidelines.rst index 208f38625..c01f02af4 100644 --- a/content/contributing/development/coding_guidelines.rst +++ b/content/contributing/development/coding_guidelines.rst @@ -490,19 +490,19 @@ Idiomatics of Programming (Python) # a bit complex and with a redundant temp variable def axes(self, axis): - axes = [] - if type(axis) == type([]): - axes.extend(axis) - else: - axes.append(axis) - return axes + axes = [] + if type(axis) == type([]): + axes.extend(axis) + else: + axes.append(axis) + return axes # clearer def axes(self, axis): - if type(axis) == type([]): - return list(axis) # clone the axis - else: - return [axis] # single-element list + if type(axis) == type([]): + return list(axis) # clone the axis + else: + return [axis] # single-element list - Know your builtins : You should at least have a basic understanding of all the Python builtins (http://docs.python.org/library/functions.html) @@ -524,7 +524,7 @@ meaning, be sure that you're using the right one. # not very good cube = [] for i in res: - cube.append((i['id'],i['name'])) + cube.append((i['id'],i['name'])) # better cube = [(i['id'], i['name']) for i in res] @@ -548,13 +548,13 @@ So, you can write ``if some_collection:`` instead of ``if len(some_collection):` # creates a temporary list and looks bar for key in my_dict.keys(): - "do something..." + "do something..." # better for key in my_dict: - "do something..." + "do something..." # accessing the key,value pair for key, value in my_dict.items(): - "do something..." + "do something..." - Use dict.setdefault