11
11
from .path i
10000
mport Path
12
12
from .transforms import (Bbox , IdentityTransform , Transform , TransformedBbox ,
13
13
TransformedPatchPath , TransformedPath )
14
- # Note, matplotlib artists use the doc strings for set and get
15
- # methods to enable the introspection methods of setp and getp. Every
16
- # set_* method should have a docstring containing the line
17
- #
18
- # ACCEPTS: [ legal | values ]
19
- #
20
- # and aliases for setters and getters should have a docstring that
21
- # starts with 'alias for ', as in 'alias for set_somemethod'
22
- #
23
- # You may wonder why we use so much boiler-plate manually defining the
24
- # set_alias and get_alias functions, rather than using some clever
25
- # python trick. The answer is that I need to be able to manipulate
26
- # the docstring, and there is no clever way to do that in python 2.2,
27
- # as far as I can see - see
28
- #
29
- # https://mail.python.org/pipermail/python-list/2004-October/242925.html
30
14
31
15
32
16
def allow_rasterization (draw ):
@@ -1181,7 +1165,7 @@ def __init__(self, o):
1181
1165
o = o [0 ]
1182
1166
1183
1167
self .oorig = o
1184
- if not inspect . isclass ( o ):
1168
+ if not isinstance ( o , type ):
1185
1169
o = type (o )
1186
1170
self .o = o
1187
1171
@@ -1220,12 +1204,9 @@ def get_valid_values(self, attr):
1220
1204
"""
1221
1205
Get the legal arguments for the setter associated with *attr*.
1222
1206
1223
- This is done by querying the docstring of the function *set_attr*
1224
- for a line that begins with "ACCEPTS" or ".. ACCEPTS":
1225
-
1226
- e.g., for a line linestyle, return
1227
- "[ ``'-'`` | ``'--'`` | ``'-.'`` | ``':'`` | ``'steps'`` | ``'None'``
1228
- ]"
1207
+ This is done by querying the docstring of the setter for a line that
1208
+ begins with "ACCEPTS:" or ".. ACCEPTS:", and then by looking for a
1209
+ numpydoc-style documentation for the setter's first argument.
1229
1210
"""
1230
1211
1231
1212
name = 'set_%s' % attr
@@ -1258,7 +1239,6 @@ def _get_setters_and_targets(self):
1258
1239
Get the attribute strings and a full path to where the setter
1259
1240
is defined for all setters in an object.
1260
1241
"""
1261
-
1262
1242
setters = []
1263
1243
for name in dir (self .o ):
1264
1244
if not name .startswith ('set_' ):
@@ -1283,10 +1263,8 @@ def _replace_path(self, source_class):
1283
1263
Changes the full path to the public API path that is used
1284
1264
in sphinx. This is needed for links to work.
1285
1265
"""
1286
-
1287
1266
replace_dict = {'_base._AxesBase' : 'Axes' ,
1288
- '_axes.Axes' : 'Axes' }
1289
-
1267
+ '_axes.Axes' : 'Axes' }
1290
1268
for key , value in replace_dict .items ():
1291
1269
source_class = source_class .replace (key , value )
1292
1270
return source_class
@@ -1296,34 +1274,25 @@ def get_setters(self):
1296
1274
Get the attribute strings with setters for object. e.g., for a line,
1297
1275
return ``['markerfacecolor', 'linewidth', ....]``.
1298
1276
"""
1299
-
1300
1277
return [prop for prop , target in self ._get_setters_and_targets ()]
1301
1278
1302
1279
def is_alias (self , o ):
1303
- """
1304
- Return *True* if method object *o* is an alias for another
1305
- function.
1306
- """
1280
+ """Return whether method object *o* is an alias for another method."""
1307
1281
ds = o .__doc__
1308
1282
if ds is None :
1309
1283
return False
1310
1284
return ds .startswith ('Alias for ' )
1311
1285
1312
1286
def aliased_name (self , s ):
1313
1287
"""
1314
- return 'PROPNAME or alias' if *s* has an alias, else return
1315
- PROPNAME.
1288
+ return 'PROPNAME or alias' if *s* has an alias, else return PROPNAME.
1316
1289
1317
1290
e.g., for the line markerfacecolor property, which has an
1318
1291
alias, return 'markerfacecolor or mfc' and for the transform
1319
1292
property, which does not, return 'transform'
1320
1293
"""
1321
-
1322
- if s in self .aliasd :
1323
- return s + '' .join ([' or %s' % x
1324
- for x in sorted (self .aliasd [s ])])
1325
- else :
1326
- return s
1294
+ return s + '' .join (' or %s' % x
1295
+ for x in sorted (self .aliasd .get (s , [])))
1327
1296
1328
1297
def aliased_name_rest (self , s , target ):
1329
1298
"""
@@ -1334,12 +1303,7 @@ def aliased_name_rest(self, s, target):
1334
1303
alias, return 'markerfacecolor or mfc' and for the transform
1335
1304
property, which does not, return 'transform'
1336
1305
"""
1337
-
1338
- if s in self .aliasd :
1339
- aliases = '' .join ([' or %s' % x
1340
- for x in sorted (self .aliasd [s ])])
1341
- else :
1342
- aliases = ''
1306
+ aliases = '' .join (' or %s' % x for x in sorted (self .aliasd .get (s , [])))
1343
1307
return ':meth:`%s <%s>`%s' % (s , target , aliases )
1344
1308
1345
1309
def pprint_setters (self , prop = None , leadingspace = 2 ):
@@ -1387,52 +1351,43 @@ def pprint_setters_rest(self, prop=None, leadingspace=4):
1387
1351
accepts = self .get_valid_values (prop )
1388
1352
return '%s%s: %s' % (pad , prop , accepts )
1389
1353
1390
- attrs = self ._get_setters_and_targets ()
1391
- attrs .sort ()
1354
+ attrs = sorted (self ._get_setters_and_targets ())
1392
1355
lines = []
1393
1356
1394
- ########
1395
1357
names = [self .aliased_name_rest (prop , target )
1396
1358
for prop , target in attrs ]
1397
1359
accepts = [self .get_valid_values (prop ) for prop , target in attrs ]
1398
1360
1399
1361
col0_len = max (len (n ) for n in names )
1400
1362
col1_len = max (len (a ) for a in accepts )
1401
-
1402
- lines .append ('' )
1403
- lines .append (pad + '.. table::' )
1404
- lines .append (pad + ' :class: property-table' )
1405
- pad += ' '
1406
-
1407
- table_formatstr = pad + '=' * col0_len + ' ' + '=' * col1_len
1408
-
1409
- lines .append ('' )
1410
- lines .append (table_formatstr )
1411
- lines .append (pad + 'Property' .ljust (col0_len + 3 ) +
1412
- 'Description' .ljust (col1_len ))
1413
- lines .append (table_formatstr )
1414
-
1415
- lines .extend ([pad + n .ljust (col0_len + 3 ) + a .ljust (col1_len )
1416
- for n , a in zip (names , accepts )])
1417
-
1418
- lines .append (table_formatstr )
1419
- lines .append ('' )
1420
- return lines
1363
+ table_formatstr = pad + ' ' + '=' * col0_len + ' ' + '=' * col1_len
1364
+
1365
+ return [
1366
+ '' ,
1367
+ pad + '.. table::' ,
1368
+ pad + ' :class: property-table' ,
1369
+ '' ,
1370
+ table_formatstr ,
1371
+ pad + ' ' + 'Property' .ljust (col0_len )
1372
+ + ' ' + 'Description' .ljust (col1_len ),
1373
+ table_formatstr ,
1374
+ * [pad + ' ' + n .ljust (col0_len ) + ' ' + a .ljust (col1_len )
1375
+ for n , a in zip (names , accepts )],
1376
+ table_formatstr ,
1377
+ '' ,
1378
+ ]
1421
1379
1422
1380
def properties (self ):
1423
- """
1424
- return a dictionary mapping property name -> value
1425
- """
1381
+ """Return a dictionary mapping property name -> value."""
1426
1382
o = self .oorig
1427
1383
getters = [name for name in dir (o )
1428
1384
if name .startswith ('get_' ) and callable (getattr (o , name ))]
1429
1385
getters .sort ()
1430
- d = dict ()
1386
+ d = {}
1431
1387
for name in getters :
1432
1388
func = getattr (o , name )
1433
1389
if self .is_alias (func ):
1434
1390
continue
1435
-
1436
1391
try :
1437
1392
with warnings .catch_warnings ():
1438
1393
warnings .simplefilter ('ignore' )
@@ -1441,14 +1396,10 @@ def properties(self):
1441
1396
continue
1442
1397
else :
1443
1398
d [name [4 :]] = val
1444
-
1445
1399
return d
1446
1400
1447
1401
def pprint_getters (self ):
1448
- """
1449
- Return the getters and actual values as list of strings.
1450
- """
1451
-
1402
+ """Return the getters and actual values as list of strings."""
1452
1403
lines = []
1453
1404
for name , val in sorted (self .properties ().items ()):
1454
1405
if getattr (val , 'shape' , ()) != () and len (val ) > 6 :
0 commit comments