Skip to content

One test fails with Python 3.11 beta 1 #3459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
frenzymadness opened this issue May 16, 2022 · 3 comments · Fixed by #3478
Closed

One test fails with Python 3.11 beta 1 #3459

frenzymadness opened this issue May 16, 2022 · 3 comments · Fixed by #3478

Comments

@frenzymadness
Copy link
Contributor

We are building RPM packges in Fedora with the latest Python 3.11 beta 1 nad ipywidgets fails:

=================================== FAILURES ===================================
___________________________ test_interact_noinspect ____________________________

    def test_interact_noinspect():
        a = u'hello'
>       c = interactive(print, a=a)

ipywidgets/widgets/tests/test_interaction.py:706: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
ipywidgets/widgets/interaction.py:201: in __init__
    self.kwargs_widgets = self.widgets_from_abbreviations(new_kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = interactive(_dom_classes=('widget-interact',))
seq = [('sep', ' ', ' '), ('end', '\n', '\n'), ('file', None, None), ('flush', False, False)]

    def widgets_from_abbreviations(self, seq):
        """Given a sequence of (name, abbrev, default) tuples, return a sequence of Widgets."""
        result = []
        for name, abbrev, default in seq:
            widget = self.widget_from_abbrev(abbrev, default)
            if not (isinstance(widget, ValueWidget) or isinstance(widget, fixed)):
                if widget is None:
>                   raise ValueError("{!r} cannot be transformed to a widget".format(abbrev))
E                   ValueError: None cannot be transformed to a widget

ipywidgets/widgets/interaction.py:301: ValueError
@frenzymadness
Copy link
Contributor Author

The problem still exists with Python 3.11b3. I'm trying to investigate it and what I know so far is that when I run the failing test with Python 3.10, the method widget_from_abbrev is called only once with abbrev="hello" and returns Text widget but with Python 3.11b3 the same function is called three times with abbrev=" ", abbrev="\n" and abbrev=None and the results are Text, Text and None. I have to find the difference causing this between 3.10 and 3.11b3.

@frenzymadness
Copy link
Contributor Author

So, the main problem is in

def find_abbreviations(self, kwargs):
"""Find the abbreviations for the given function and kwargs.
Return (name, abbrev, default) tuples.
"""
new_kwargs = []
try:
sig = self.signature()
except (ValueError, TypeError):
# can't inspect, no info from function; only use kwargs
return [ (key, value, value) for key, value in kwargs.items() ]
for param in sig.parameters.values():
for name, value, default in _yield_abbreviations_for_parameter(param, kwargs):
if value is empty:
raise ValueError('cannot find widget or abbreviation for argument: {!r}'.format(name))
new_kwargs.append((name, value, default))
return new_kwargs

The main difference is the signature of the print function:

Python 3.10.4 (main, Mar 25 2022, 00:00:00) [GCC 12.0.1 20220308 (Red Hat 12.0.1-0)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from inspect import signature
>>> signature(print)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.10/inspect.py", line 3247, in signature
    return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
  File "/usr/lib64/python3.10/inspect.py", line 2995, in from_callable
    return _signature_from_callable(obj, sigcls=cls,
  File "/usr/lib64/python3.10/inspect.py", line 2461, in _signature_from_callable
    return _signature_from_builtin(sigcls, obj,
  File "/usr/lib64/python3.10/inspect.py", line 2271, in _signature_from_builtin
    raise ValueError("no signature found for builtin {!r}".format(func))
ValueError: no signature found for builtin <built-in function print>

Python 3.11.0b3 (main, Jun  1 2022, 00:00:00) [GCC 12.1.1 20220507 (Red Hat 12.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from inspect import signature
>>> signature(print)
<Signature (*args, sep=' ', end='\n', file=None, flush=False)>

In the code of the function below, it's expected that getting the print function's signature raises the exception that is no longer true in Python 3.11.

When the signature is investigated, new_kwargs in the __init__ method contains: [('sep', ' ', ' '), ('end', '\n', '\n'), ('file', None, None), ('flush', False, False)] and I guess the default value for flush is the problem here because you there is no default plugin for None.

If I understand the test correctly, its purpose is to test a function without an existing signature so I think we can just use something different than print. I'll try to prepare a PR.

frenzymadness added a commit to frenzymadness/ipywidgets that referenced this issue Jun 8, 2022
In Python 3.11, `inspect.signature(print)` no longer raises
ValueError.

Fixes: jupyter-widgets#3459
@jasongrout
Copy link
Member

I'll try to prepare a PR.

Thanks for diving into this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants