summaryrefslogtreecommitdiff
path: root/astroid/util.py
diff options
context:
space:
mode:
authorBryce Guinta <bryce.paul.guinta@gmail.com>2018-07-05 15:51:36 -0600
committerBryce Guinta <bryce.guinta@protonmail.com>2018-07-06 03:08:54 -0600
commitc1ba448bf2684ef3704f49ec5e170662adfc4edf (patch)
tree68f41c7cf15e188a53e15857f8a253ce98e4a7c3 /astroid/util.py
parent0b7638a0d2a1d29b3bba690e779dd02d89dbac81 (diff)
downloadastroid-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.py24
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