Repository: spyder-ide/spyder

Issue:
Not all lists are supported by the variable explorer
**What steps will reproduce the problem?**

1. Create two lists `a = [len, 1]` and `b = [1, len]` 
2. Check the variable explorer
3. `a` is not supported while `b` is

**What is the expected output? What do you see instead?**
Both `a` and `b` are lists. They should be both supported.


Discussion:
This is caused by the [`is_supported`](https://github.com/spyder-ide/spyder/blob/master/spyder/widgets/variableexplorer/utils.py#L511) functions. By default it checks the first item of iterables and if the first item is not supported (like `len`) the whole `list` is considered as not supported. 
@Prikers, do you want to work on this one?
Yes I will. I just need input from you to know where we want to go with this one. So far we have this behavior:
```python
def is_supported(value, check_all=False, filters=None, iterate=True):
    """Return True if the value is supported, False otherwise"""
    (...) # omitted from brevity
    elif iterate:
        if isinstance(value, (list, tuple, set)):
            valid_count = 0
            for val in value:
                if is_supported(val, filters=filters, iterate=check_all):
                    valid_count += 1
                if not check_all:
                    break
            return valid_count > 0
    (...) # omitted from brevity
```
- Do we want to display all lists even if they contain one non-supported object anywhere? (:+1:)
- Or the opposite? 
What does supported mean in this context? I know unsupported objects are not displayed in the variable explorer by default, but is that all?

My first thought is: we display all lists (even if they contain only non-supported objects). I think this minimizes confusion.

Things to keep in mind:
* Very long lists should not lead to unresponsive GUI
* Lists containing itself should not cause problems
* I believe dicts and lists are not handled consistently at the moment
> What does supported mean in this context? I know unsupported objects are not displayed in the variable explorer by default, but is that all?

Yes that's it. By turning on the option to display unsupported object the list `[len, 1]` would appear
> Do we want to display all lists even if they contain one non-supported object anywhere?

I think this is the best option @Prikers.

Resolving patch:
diff --git a/spyder/widgets/variableexplorer/utils.py b/spyder/widgets/variableexplorer/utils.py
--- a/spyder/widgets/variableexplorer/utils.py
+++ b/spyder/widgets/variableexplorer/utils.py
@@ -504,7 +504,7 @@ def get_human_readable_type(item):
 # Globals filter: filter namespace dictionaries (to be edited in
 # CollectionsEditor)
 #==============================================================================
-def is_supported(value, check_all=False, filters=None, iterate=True):
+def is_supported(value, check_all=False, filters=None, iterate=False):
     """Return True if the value is supported, False otherwise"""
     assert filters is not None
     if value is None:


Test patch:
diff --git a/spyder/widgets/variableexplorer/tests/test_utils.py b/spyder/widgets/variableexplorer/tests/test_utils.py
--- a/spyder/widgets/variableexplorer/tests/test_utils.py
+++ b/spyder/widgets/variableexplorer/tests/test_utils.py
@@ -112,6 +112,11 @@ def test_list_display():
     result = '[defaultdict, Panel, 1, {1:2, 3:4}, Dataframe]'
     assert value_to_display(li) == result
 
+    # List starting with a non-supported object (#5313)
+    supported_types = tuple(get_supported_types()['editable'])
+    li = [len, 1]
+    assert value_to_display(li) == '[builtin_function_or_method, 1]'
+    assert is_supported(li, filters=supported_types)
 
 def test_dict_display():
     """Tests for display of dicts."""
@@ -148,6 +153,14 @@ def test_dict_display():
     result = '{0:defaultdict, 1:Panel, 2:2, 3:{0:0, 1:1}, 4:Dataframe}'
     assert value_to_display(li) == result
 
+    # Dict starting with a non-supported object (#5313)
+    supported_types = tuple(get_supported_types()['editable'])
+    di = {max: len, 1: 1}
+    assert value_to_display(di) in (
+            '{builtin_function_or_method:builtin_function_or_method, 1:1}',
+            '{1:1, builtin_function_or_method:builtin_function_or_method}')
+    assert is_supported(di, filters=supported_types)
+
 
 if __name__ == "__main__":
     pytest.main()