@@ -396,8 +396,8 @@ def _default_contains(self, mouseevent, figure=None):
396
396
return inside, info
397
397
# subclass-specific implementation follows
398
398
399
- The *figure * kwarg is provided for the implementation of
400
- `Figure.contains`.
399
+ The *canvas * kwarg is provided for the implementation of
400
+ `. Figure.contains`.
401
401
"""
402
402
if callable (self ._contains ):
403
403
return self ._contains (self , mouseevent )
@@ -1304,24 +1304,6 @@ def get_valid_values(self, attr):
1304
1304
1305
1305
return 'unknown'
1306
1306
1307
- def _get_setters_and_targets (self ):
1308
- """
1309
- Get the attribute strings and a full path to where the setter
1310
- is defined for all setters in an object.
1311
- """
1312
- setters = []
1313
- for name in dir (self .o ):
1314
- if not name .startswith ('set_' ):
1315
- continue
1316
- func = getattr (self .o , name )
1317
- if (not callable (func )
1318
- or len (inspect .signature (func ).parameters ) < 2
1319
- or self .is_alias (func )):
1320
- continue
1321
- setters .append (
1322
- (name [4 :], f"{ func .__module__ } .{ func .__qualname__ } " ))
1323
- return setters
1324
-
1325
1307
def _replace_path (self , source_class ):
1326
1308
"""
1327
1309
Changes the full path to the public API path that is used
@@ -1338,7 +1320,17 @@ def get_setters(self):
1338
1320
Get the attribute strings with setters for object. e.g., for a line,
1339
1321
return ``['markerfacecolor', 'linewidth', ....]``.
1340
1322
"""
1341
- return [prop for prop , target in self ._get_setters_and_targets ()]
1323
+ setters = []
1324
+ for name in dir (self .o ):
1325
+ if not name .startswith ('set_' ):
1326
+ continue
1327
+ func = getattr (self .o , name )
1328
+ if (not callable (func )
1329
+ or len (inspect .signature (func ).parameters ) < 2
1330
+ or self .is_alias (func )):
1331
+ continue
1332
+ setters .append (name [4 :])
1333
+ return setters
1342
1334
1343
1335
def is_alias (self , o ):
1344
1336
"""Return whether method object *o* is an alias for another method."""
@@ -1387,24 +1379,20 @@ def pprint_setters(self, prop=None, leadingspace=2):
1387
1379
accepts = self .get_valid_values (prop )
1388
1380
return '%s%s: %s' % (pad , prop , accepts )
1389
1381
1390
- attrs = self ._get_setters_and_targets ()
1391
- attrs .sort ()
1392
1382
lines = []
1393
-
1394
- for prop , path in attrs :
1383
+ for prop in sorted (self .get_setters ()):
1395
1384
accepts = self .get_valid_values (prop )
1396
1385
name = self .aliased_name (prop )
1397
-
1398
1386
lines .append ('%s%s: %s' % (pad , name , accepts ))
1399
1387
return lines
1400
1388
1401
1389
def pprint_setters_rest (self , prop = None , leadingspace = 4 ):
1402
1390
"""
1403
- If *prop* is *None*, return a list of strings of all settable
1404
- properties and their valid values. Format the output for ReST
1391
+ If *prop* is *None*, return a list of ReST-formatted strings of all
1392
+ settable properties and their valid values.
1405
1393
1406
1394
If *prop* is not *None*, it is a valid property name and that
1407
- property will be returned as a string of property : valid
1395
+ property will be returned as a string of " property : valid"
1408
1396
values.
1409
1397
"""
1410
1398
if leadingspace :
@@ -1415,13 +1403,24 @@ def pprint_setters_rest(self, prop=None, leadingspace=4):
1415
1403
accepts = self .get_valid_values (prop )
1416
1404
return '%s%s: %s' % (pad , prop , accepts )
1417
1405
1418
- attrs = sorted (self ._get_setters_and_targets ())
1419
-
1420
- names = [self .aliased_name_rest (prop , target ).replace (
1421
- '_base._AxesBase' , 'Axes' ).replace (
1422
- '_axes.Axes' , 'Axes' )
1423
- for prop , target in attrs ]
1424
- accepts = [self .get_valid_values (prop ) for prop , target in attrs ]
1406
+ prop_and_qualnames = []
1407
+ for prop in sorted (self .get_setters ()):
1408
+ # Find the parent method which actually provides the docstring.
1409
+ for cls in self .o .__mro__ :
1410
+ method = getattr (cls , f"set_{ prop } " , None )
1411
+ if method and method .__doc__ is not None :
1412
+ break
1413
+ else : # No docstring available.
1414
+ method = getattr (self .o , f"set_{ prop } " )
1415
+ prop_and_qualnames .append (
1416
+ (prop , f"{ method .__module__ } .{ method .__qualname__ } " ))
1417
+
1418
+ names = [self .aliased_name_rest (prop , target )
1419
+ .replace ('_base._AxesBase' , 'Axes' )
1420
+ .replace ('_axes.Axes' , 'Axes' )
1421
+ for prop , target in prop_and_qualnames ]
1422
+ accepts = [self .get_valid_values (prop )
1423
+ for prop , _ in prop_and_qualnames ]
1425
1424
1426
1425
col0_len = max (len (n ) for n in names )
1427
1426
col1_len = max (len (a ) for a in accepts )
0 commit comments