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

Skip to content

Commit be04a59

Browse files
authored
Merge pull request #23759 from meeseeksmachine/auto-backport-of-pr-23686-on-v3.6.x
Backport PR #23686 on branch v3.6.x (Improve matplotlib.pyplot importtime by caching ArtistInspector)
2 parents 5823ec9 + 4d99a79 commit be04a59

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

lib/matplotlib/artist.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections import namedtuple
22
import contextlib
3-
from functools import wraps
3+
from functools import lru_cache, wraps
44
import inspect
55
from inspect import Signature, Parameter
66
import logging
@@ -1494,17 +1494,29 @@ def get_setters(self):
14941494
continue
14951495
func = getattr(self.o, name)
14961496
if (not callable(func)
1497-
or len(inspect.signature(func).parameters) < 2
1497+
or self.number_of_parameters(func) < 2
14981498
or self.is_alias(func)):
14991499
continue
15001500
setters.append(name[4:])
15011501
return setters
15021502

1503-
def is_alias(self, o):
1504-
"""Return whether method object *o* is an alias for another method."""
1505-
ds = inspect.getdoc(o)
1503+
@staticmethod
1504+
@lru_cache(maxsize=None)
1505+
def number_of_parameters(func):
1506+
"""Return number of parameters of the callable *func*."""
1507+
return len(inspect.signature(func).parameters)
1508+
1509+
@staticmethod
1510+
@lru_cache(maxsize=None)
1511+
def is_alias(method):
1512+
"""
1513+
Return whether the object *method* is an alias for another method.
1514+
"""
1515+
1516+
ds = inspect.getdoc(method)
15061517
if ds is None:
15071518
return False
1519+
15081520
return ds.startswith('Alias for ')
15091521

15101522
def aliased_name(self, s):

0 commit comments

Comments
 (0)