Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit feab121

Browse files
committed
Sped up get_valid_values to improve startup time.
svn path=/trunk/matplotlib/; revision=3749
1 parent 2697d38 commit feab121

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

lib/matplotlib/artist.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import division
2-
import sys
2+
import sys, re
33
from cbook import iterable, flatten
44
from transforms import identity_transform
55
import matplotlib.units as units
@@ -484,6 +484,7 @@ def get_aliases(self):
484484
aliases[fullname[4:]] = name[4:]
485485
return aliases
486486

487+
_get_valid_values_regex = re.compile(r"\n\s*ACCEPTS:\s*(.*)\n")
487488
def get_valid_values(self, attr):
488489
"""
489490
get the legal arguments for the setter associated with attr
@@ -505,10 +506,10 @@ def get_valid_values(self, attr):
505506

506507
if docstring.startswith('alias for '):
507508
return None
508-
for line in docstring.split('\n'):
509-
line = line.lstrip()
510-
if not line.startswith('ACCEPTS:'): continue
511-
return line[8:].strip()
509+
510+
match = self._get_valid_values_regex.search(docstring)
511+
if match is not None:
512+
return match.group(1)
512513
return 'unknown'
513514

514515
def get_setters(self):

0 commit comments

Comments
 (0)