python
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
python [2019/08/09 16:41] – [Coding Rules] francois | python [2019/09/10 14:52] (Version actuelle) – francois | ||
---|---|---|---|
Ligne 75: | Ligne 75: | ||
===== Fundamental Rules ===== | ===== Fundamental Rules ===== | ||
- | == RUL_GEN_001 | + | == RUL_GEN_001 Important Rule == |
- | A comment is there to explain the code not to rephrase it.\\ | + | |
- | Comment shall not contradict the code, update the comment with the code. | + | |
- | + | ||
- | == RUL_GEN_002 | + | |
<note tip> | <note tip> | ||
If you don't understand why you should not modify a line, **DON' | If you don't understand why you should not modify a line, **DON' | ||
</ | </ | ||
- | == RUL_GEN_003 | + | |
+ | == RUL_GEN_002 | ||
Don't modify a line just to make it nicer, better, what ever justification you want, until there is a declared issue or an enhancement or task assigned to you linked with the line. | Don't modify a line just to make it nicer, better, what ever justification you want, until there is a declared issue or an enhancement or task assigned to you linked with the line. | ||
- | == RUL_GEN_004 | + | == RUL_GEN_004 |
<note warning> | <note warning> | ||
**In any case, Keep it simple** | **In any case, Keep it simple** | ||
</ | </ | ||
+ | |||
+ | == RUL_GEN_005 Guru rule== | ||
+ | |||
+ | Do what I say, Don't do what I do. | ||
+ | |||
+ | ===== Comment Rules ===== | ||
+ | |||
+ | == RUL_CMT_001 Comments == | ||
+ | A comment is there to explain the code not to rephrase it.\\ | ||
+ | Comment shall not contradict the code, update the comment with the code. | ||
+ | |||
+ | == RUL_CMT_002 Doc Strings == | ||
+ | Always use DocStrings for Files, Class and functions comment block.\\ | ||
+ | |||
+ | == RUL_CMT_004 DocString is for users == | ||
+ | DocString section is for user of the element not for developper/ | ||
+ | |||
+ | == RUL_CMT_003 Maintainer comments == | ||
+ | Use standard comment immediatly of SocString section for developper/ | ||
===== Coding Rules ===== | ===== Coding Rules ===== | ||
== RUL_COD_001 : Python version == | == RUL_COD_001 : Python version == | ||
- | Python 3.6 is the preferred Python version. If Python2 is required use Python 2.7.< | + | Python 3.7 is the preferred Python version. If Python2 is required use Python 2.7.< |
Ligne 101: | Ligne 117: | ||
== RUL_COD_003 == | == RUL_COD_003 == | ||
- | Use Pylint to check to compliance of your and **AND FIX ALL WARNINGS**.\\ Justification | + | Use Pylint to check to compliance of your code **AND FIX ALL WARNINGS**.\\ Justification |
Ligne 107: | Ligne 123: | ||
==== Edition Rule ==== | ==== Edition Rule ==== | ||
- | == RUL_COD_003 | + | == RUL_WRI_001 |
- | Configure your editor to replace TAB character by **4 spaces**. If your editor is not enable to replace automatically don't use TAB. | + | Configure your editor to replace TAB character by **4 spaces**. If your editor is not enable to replace automatically, don't use TAB or better change your editor to another one. |
- | == RUL_COD_004 | + | == RUL_WRI_002 |
Make sure your environment is configured to use only ' | Make sure your environment is configured to use only ' | ||
# -- coding: | # -- coding: | ||
- | == RUL_COD_005 | + | == RUL_WRI_003 |
- | Make your Python2 code compliant with Python3 by inserting at least : | + | |
- | | + | Make your Python2 code compliant with Python3 by inserting at least : (from [[https:// |
+ | |||
+ | from __future__ import absolute_import | ||
+ | | ||
from __future__ import print_function | from __future__ import print_function | ||
+ | from __future__ import unicode_literals | ||
+ | | ||
+ | from builtins import * | ||
+ | | ||
+ | from future import standard_library | ||
+ | standard_library.install_aliases() | ||
+ | |||
| | ||
- | == RUL_COD_006 | + | == RUL_WRI_004 |
- | Always use **4 spaces** indentation except for function arguments indentation. | + | Always use **4 spaces** indentation except for function arguments indentation.(see PEP008) |
==== Strings ==== | ==== Strings ==== | ||
+ | |||
== RUL_STR_01 bytes storage (was: str usage) == | == RUL_STR_01 bytes storage (was: str usage) == | ||
Python2: Use '' | Python2: Use '' | ||
Ligne 129: | Ligne 155: | ||
== RUL_STR_002 QString usage == | == RUL_STR_002 QString usage == | ||
+ | |||
Use '' | Use '' | ||
== RUL_STR_003 Use unicode == | == RUL_STR_003 Use unicode == | ||
+ | |||
For all other strings use '' | For all other strings use '' | ||
=== Classes === | === Classes === | ||
+ | == RUL_CLS_001 Forget old-style class == | ||
+ | |||
+ | Python 2: Any class MUST inherit directly or indirectly from ``object``. | ||
+ | |||
+ | == RUL_CLS_002 == | ||
+ | |||
+ | Use ``self`` to identify instance parameter and ``cls`` for class related parameter. | ||
+ | |||
+ | == RUL_CLS_003 == | ||
+ | |||
+ | |||
python.1565368900.txt.gz · Dernière modification : 2019/08/09 16:41 de francois