@@ -21,18 +21,18 @@ in mind.
21
21
running simple_plot.py or image_demo.py with --Numeric, --numarray
22
22
and --numpy (Note, someone should add examples to
23
23
backend_driver.py which explicitly require numpy, numarray and
24
- Numeric so we can automatically catch these
24
+ Numeric so we can automatically catch these)
25
25
26
- * Can you pass examples/backend_driver.py . This is our poor man's
27
- unit test
26
+ * Can you pass examples/backend_driver.py? This is our poor man's
27
+ unit test.
28
28
29
29
* If you have altered extension code, do you pass
30
- unit/memleak_hawaii.py
30
+ unit/memleak_hawaii.py?
31
31
32
32
33
33
== Naming conventions ==
34
34
35
- functions and class methods : undercase_separated_lower
35
+ functions and class methods : lower or lower_underscore_separated
36
36
37
37
attributes and variables : lower or lowerUpper
38
38
@@ -42,7 +42,7 @@ Personally, I prefer the shortest names that are still readable.
42
42
43
43
== kwargs processing ==
44
44
45
- Matplotlib makes extensive use of kwargs so pass through
45
+ Matplotlib makes extensive use of ** kwargs for pass through
46
46
customizations from one function to another, eg the pylab plot ->
47
47
Axes.plot pass through. As a general rule, the use of **kwargs should
48
48
be reserved for pass-through keyword arguments, eg
@@ -51,16 +51,18 @@ be reserved for pass-through keyword arguments, eg
51
51
# do some thing with x, k1
52
52
return some_other_func(..., **kwargs)
53
53
54
- If I intend for all the kwargs to be used in somefunc alone, I just
55
- use the key/value keyword args in the function definition rather than
56
- the **kwargs idiom. In some cases I want to consume some keys and
57
- pass through the others, in which case I pop the ones I want to use
58
- locally and pass on the rest, eg I pop scalex and scaley in Axes.plot
59
- and assume the rest are Line2D args. Whenever you mutate a kwargs
60
- dictionary, you must first copy it since the user may be explitly
61
- passing in a dictionary which is used across many function calls, eg,
62
- in Axes.plot
54
+ If I intend for all the keyword args to be used in somefunc alone, I
55
+ just use the key/value keyword args in the function definition rather
56
+ than the **kwargs idiom. In some cases I want to consume some keys
57
+ and pass through the others, in which case I pop the ones I want to
58
+ use locally and pass on the rest, eg I pop scalex and scaley in
59
+ Axes.plot and assume the rest are Line2D keyword arguments. Whenever
60
+ you mutate a kwargs dictionary (eg by popping it), you must first copy
61
+ it since the user may be explitly passing in a dictionary which is
62
+ used across many function calls. As an example of a copy, pop,
63
+ passthrough usage, see Axes.plot:
63
64
65
+ def plot(self, *args, **kwargs):
64
66
kwargs = kwargs.copy()
65
67
scalex = popd(kwargs, 'scalex', True)
66
68
scaley = popd(kwargs, 'scaley', True)
@@ -70,14 +72,15 @@ in Axes.plot
70
72
self.add_line(line)
71
73
lines.append(line)
72
74
73
- popd is a matplotlib.cbook function.
75
+ popd is a matplotlib.cbook function to pop an item from a dictionary
76
+ with a default value if the item doesn't exist
74
77
75
78
Note there is a use case when kwargs are meant to be used locally in
76
- the function, but you still need the **kwargs idiom. That is when you
77
- want to use *args to allow variable numbers of non keyword args. In
78
- this case, python will not allow you to use named keyword args after
79
- the *args usage, so you will be forces to use kwargs. An example is
80
- matplotlib.contour.ContourLabeler.clabel
79
+ the function (not passed on) , but you still need the **kwargs idiom.
80
+ That is when you want to use *args to allow variable numbers of
81
+ non-keyword args. In this case, python will not allow you to use
82
+ named keyword args after the *args usage, so you will be forced to use
83
+ **kwargs. An example is matplotlib.contour.ContourLabeler.clabel
81
84
82
85
def clabel(self, *args, **kwargs):
83
86
fontsize = kwargs.get('fontsize', None)
@@ -98,7 +101,7 @@ matplotlib uses artist instrospection of docstrings to support
98
101
properties. All properties that you want to support through setp and
99
102
getp should have a set_property and get_property method in the Artist
100
103
class. Yes this is not ideal given python properties or enthought
101
- traits but it is a historical legacy for now. The setter methods use
104
+ traits, but it is a historical legacy for now. The setter methods use
102
105
the docstring with the ACCEPTS token to indicate the type of argument
103
106
the method accepts. Eg in matplotlib.lines.Line2D
104
107
@@ -120,8 +123,8 @@ requirements are:
120
123
1) single point of configuration so changes to the properties don't
121
124
require multiple docstring edits
122
125
123
- 2) as automated as possible so that as setters and getters change
124
- the docs are updated automagically.
126
+ 2) as automated as possible so that as properties change the docs
127
+ are updated automagically.
125
128
126
129
I have added a matplotlib.artist.kwdocd to faciliate this. This
127
130
combines python string interpolation in the docstring with the
@@ -149,4 +152,11 @@ matplotlib.axes.Axes.plot
149
152
pass
150
153
plot.__doc__ = plot.__doc__ % artist.kwdocd
151
154
155
+ Note there is a problem for Artist __init__ methods, eg
156
+ Patch.__init__ which supports Patch kwargs, since the artist inspector
157
+ cannot work until the class is fully defined and we can't modify the
158
+ Patch.__init__.__doc__ docstring outside the class definition. I have
159
+ made some manual hacks in this case which violates the "single entry
160
+ point" requirement above; hopefully we'll find a more elegant solution
161
+ before too long
152
162
0 commit comments