diff options
author | Bryce Guinta <bryce.paul.guinta@gmail.com> | 2018-07-05 15:51:36 -0600 |
---|---|---|
committer | Bryce Guinta <bryce.guinta@protonmail.com> | 2018-07-06 03:08:54 -0600 |
commit | c1ba448bf2684ef3704f49ec5e170662adfc4edf (patch) | |
tree | 68f41c7cf15e188a53e15857f8a253ce98e4a7c3 /astroid/util.py | |
parent | 0b7638a0d2a1d29b3bba690e779dd02d89dbac81 (diff) | |
download | astroid-git-c1ba448bf2684ef3704f49ec5e170662adfc4edf.tar.gz |
Limit inference to a maximum of 100 results at a time to prevent
spot performance issues.
Add new envrionment variable call ASTROID_MAX_INFERABLE to tune
the max inferable amount of values at a time.
Close #579
Close PyCQA/pylint#2251
Diffstat (limited to 'astroid/util.py')
-rw-r--r-- | astroid/util.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/astroid/util.py b/astroid/util.py index a5310970..8497b34a 100644 --- a/astroid/util.py +++ b/astroid/util.py @@ -5,6 +5,7 @@ # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER import warnings +from itertools import islice import importlib import lazy_object_proxy @@ -126,5 +127,28 @@ def proxy_alias(alias_name, node_type): return proxy(lambda: node_type) +def limit_inference(iterator, size): + """Limit inference amount. + + Limit inference amount to help with performance issues with + exponentially exploding possible results. + + :param iterator: Inference generator to limit + :type iterator: Iterator(NodeNG) + + :param size: Maximum mount of nodes yielded plus an + Uninferable at the end if limit reached + :type size: int + + :yields: A possibly modified generator + :rtype param: Iterable + """ + yield from islice(iterator, size) + has_more = next(iterator, False) + if has_more is not False: + yield Uninferable + return + + # Backwards-compatibility aliases YES = Uninferable |