Mercurial > pylearn
annotate doc/v2_planning/API_coding_style.txt @ 1147:f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
author | Olivier Delalleau <delallea@iro> |
---|---|
date | Thu, 16 Sep 2010 16:24:47 -0400 |
parents | d6d73a9f07b8 |
children | 2da593b0f29d |
rev | line source |
---|---|
1143
fa1715e759e3
Added API file for coding style committee (now we just need to fill it)
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
1 ========================= |
fa1715e759e3
Added API file for coding style committee (now we just need to fill it)
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
2 Coding Style Guidelines |
fa1715e759e3
Added API file for coding style committee (now we just need to fill it)
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
3 ========================= |
fa1715e759e3
Added API file for coding style committee (now we just need to fill it)
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
4 |
1145
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
5 Main Goals |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
6 ========== |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
7 |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
8 * Code should be compatible with Python 2.4 and above (using 2to3 for |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
9 conversion to Python 3.x). This may not be possible in the short term |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
10 for code dependent on Theano. |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
11 |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
12 * Code should be easy to read, understand and update by developers and |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
13 users. |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
14 |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
15 * Code should be well-documented and well-tested. |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
16 |
1143
fa1715e759e3
Added API file for coding style committee (now we just need to fill it)
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
17 Code Sample |
fa1715e759e3
Added API file for coding style committee (now we just need to fill it)
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
18 =========== |
fa1715e759e3
Added API file for coding style committee (now we just need to fill it)
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
19 |
fa1715e759e3
Added API file for coding style committee (now we just need to fill it)
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
20 The following code sample illustrates many of the coding guidelines one should |
fa1715e759e3
Added API file for coding style committee (now we just need to fill it)
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
21 follow in Pylearn. |
fa1715e759e3
Added API file for coding style committee (now we just need to fill it)
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
22 |
fa1715e759e3
Added API file for coding style committee (now we just need to fill it)
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
23 .. code-block:: python |
fa1715e759e3
Added API file for coding style committee (now we just need to fill it)
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
24 |
fa1715e759e3
Added API file for coding style committee (now we just need to fill it)
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
25 import os, sys, time |
fa1715e759e3
Added API file for coding style committee (now we just need to fill it)
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
26 |
1145
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
27 Python Coding Guidelines |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
28 ======================== |
1143
fa1715e759e3
Added API file for coding style committee (now we just need to fill it)
Olivier Delalleau <delallea@iro>
parents:
diff
changeset
|
29 |
1145
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
30 Official Guidelines |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
31 ------------------- |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
32 |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
33 Source Material |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
34 ~~~~~~~~~~~~~~~ |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
35 |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
36 The three main documents describing our Python coding guidelines are: |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
37 * `PEP 8 -- Style Guide for Python Code |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
38 <http://www.python.org/dev/peps/pep-0008>`_ |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
39 * `PEP 257 -- Docstring Conventions |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
40 <http://www.python.org/dev/peps/pep-0257>`_ |
1147
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
41 * `Numpy Docstring Standard |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
42 <http://projects.scipy.org/numpy/wiki/CodingStyleGuidelines#docstring-standard>`_ |
1145
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
43 * `Google Python Style Guide |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
44 <http://google-styleguide.googlecode.com/svn/trunk/pyguide.html>`_ |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
45 |
1147
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
46 |
1145
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
47 However, there are a few points mentioned in those documents that we decided |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
48 to do differently: |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
49 |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
50 * Use only one space (not two) after a sentence-ending period in comments. |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
51 |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
52 Excerpts |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
53 ~~~~~~~~ |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
54 |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
55 We emphasize here a few important topics that are found in the official |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
56 guidelines: |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
57 |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
58 Additional Recommendations |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
59 -------------------------- |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
60 |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
61 Things you should do even if they are not listed in official guidelines: |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
62 |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
63 * Avoid backslashes whenever possible. They make it more |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
64 difficult to edit code, and they are ugly (as well as potentially |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
65 dangerous if there are trailing white spaces). |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
66 |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
67 .. code-block:: python |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
68 |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
69 # Good. |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
70 if (cond_1 and |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
71 cond_2 and |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
72 cond_3): |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
73 ... |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
74 # Bad. |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
75 if cond_1 and \ |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
76 cond_2 and \ |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
77 cond_3: |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
78 ... |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
79 |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
80 * When indenting multi-line statements like lists or function arguments, |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
81 keep elements of the same level aligned with each other. |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
82 The position of the first |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
83 element (on the same line or a new line) should be chosen depending on |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
84 what is easiest to read (sometimes both can be ok). |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
85 |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
86 .. code-block:: python |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
87 |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
88 # Good. |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
89 for my_very_long_variable_name in [my_food, my_bar, my_love, |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
90 my_everything]: |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
91 ... |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
92 for my_very_long_variable_name in [ |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
93 my_foo, my_bar, my_love, my_everything]: |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
94 ... |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
95 # Good iff the list needs to be frequently updated. |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
96 for my_very_long_variable_name in [ |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
97 my_foo, |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
98 my_bar, |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
99 my_love, |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
100 my_everything, |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
101 ]: |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
102 ... |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
103 # Bad. |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
104 for my_very_long_variable_name in [my_foo, my_bar, my_love, |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
105 my_everything]: |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
106 ... |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
107 for my_very_long_variable_name in [my_foo, |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
108 my_bar, |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
109 my_love, |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
110 my_everything]: |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
111 ... |
d6d73a9f07b8
API_coding_style: Started to work on official guidelines
Olivier Delalleau <delallea@iro>
parents:
1143
diff
changeset
|
112 |
1147
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
113 The ``logging`` Module vs. the ``warning`` Module |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
114 ================================================= |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
115 |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
116 The ``logging`` Module |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
117 ---------------------- |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
118 |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
119 A central logging facility for Python capable of logging messages of various |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
120 categories/urgency and choosing with some granularity which messages are |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
121 displayed/suppressed, as well as where they are displayed or written. This |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
122 includes an ``INFO`` level for innocuous status information, a ``WARNING`` level |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
123 for unexpected state that is still recoverable, ``DEBUG`` for detailed |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
124 information which is only really of interest when things are going wrong, etc. |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
125 |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
126 In addition to the `library documentation`_, see this helpful tutorial, |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
127 `Python Logging 101`_. |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
128 |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
129 .. _library documentation: http://docs.python.org/library/logging.html |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
130 .. _Python Logging 101: http://plumberjack.blogspot.com/2009/09/python-logging-101.html |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
131 |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
132 The ``warning`` Module |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
133 ---------------------- |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
134 |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
135 The ``warning`` module in the standard library and its main interface, the |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
136 ``warn()`` function, allows the programmer to issue warnings in situations where |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
137 they wish to alert the user to some condition, but the situation is not |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
138 urgent enough to throw an exception. By default, a warning issued at a given |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
139 line of the code will only be displayed the first time that line is executed. |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
140 By default, warnings are written to ``sys.stderr`` but the ``warning`` module |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
141 contains flexible facilities for altering the defaults, redirecting, etc. |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
142 |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
143 Which? When? |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
144 ------------ |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
145 |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
146 It is our feeling that the ``logging`` module's ``WARNING`` level be used to log |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
147 warnings more meant for *internal*, *developer* consumption, to log situations |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
148 where something unexpected happened that may be indicative of a problem but |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
149 is several layers of abstraction below what a user of the library would |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
150 care about. |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
151 |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
152 By contrast, the warning module should be used for warnings intended for user |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
153 consumption, e.g. alerting them that their version of Pylearn is older than |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
154 this plugin requires, so things may not work as expected, or that a given |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
155 function/class/method is slated for deprecation in a coming release (early |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
156 in the library's lifetime, ``DeprecationWarning`` will likely be the most common |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
157 case). The warning message issued through this facility should avoid |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
158 referring to Pylearn internals. |
f6011a2aff0b
coding_style: Moved David's comments from coding_style.txt to API_coding_style.txt
Olivier Delalleau <delallea@iro>
parents:
1145
diff
changeset
|
159 |