Skip to content
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

extract_lambda_source fails in Pyodide #3438

Closed
Zac-HD opened this issue Aug 12, 2022 · 1 comment · Fixed by #3440
Closed

extract_lambda_source fails in Pyodide #3438

Zac-HD opened this issue Aug 12, 2022 · 1 comment · Fixed by #3440
Labels
bug something is clearly wrong here interop how to play nicely with other packages

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Aug 12, 2022

If you paste the following code into my online ghostwriter demo, you get an error:

from hypothesis import given, strategies as st

@given(st.just(lambda: None))
def test_extract_lambda_source(obj):
    assert False
Traceback (most recent call last):
  File "test_code.py", line 6, in test_extract_lambda_source
    #
  File "/lib/python3.10/site-packages/hypothesis/core.py", line 1257, in wrapped_test
    raise the_error_hypothesis_found
  File "/lib/python3.10/site-packages/hypothesis/core.py", line 1224, in wrapped_test
    state.run_engine()
  File "/lib/python3.10/site-packages/hypothesis/core.py", line 903, in run_engine
    _raise_to_user(errors_to_report, self.settings, report_lines)
  File "/lib/python3.10/site-packages/hypothesis/core.py", line 934, in _raise_to_user
    raise the_error_hypothesis_found
  File "/lib/python3.10/site-packages/hypothesis/core.py", line 866, in run_engine
    self.execute_once(
  File "/lib/python3.10/site-packages/hypothesis/core.py", line 688, in execute_once
    result = self.test_runner(data, run)
  File "/lib/python3.10/site-packages/hypothesis/executors.py", line 47, in default_new_style_executor
    return function(data)
  File "/lib/python3.10/site-packages/hypothesis/core.py", line 649, in run
    text_repr = repr_call(test, args, kwargs)
  File "/lib/python3.10/site-packages/hypothesis/internal/reflection.py", line 421, in repr_call
    bits.append(f"{p.name}={nicerepr(kwargs.pop(p.name))}")
  File "/lib/python3.10/site-packages/hypothesis/internal/reflection.py", line 405, in nicerepr
    return get_pretty_function_description(v)
  File "/lib/python3.10/site-packages/hypothesis/internal/reflection.py", line 390, in get_pretty_function_description
    return extract_lambda_source(f)
  File "/lib/python3.10/site-packages/hypothesis/internal/reflection.py", line 279, in extract_lambda_source
    assert "lambda" in source
AssertionError

I'm not sure exactly why, but it would be nice to fix this (and use #3437 to prevent a regression).

@Zac-HD Zac-HD added bug something is clearly wrong here interop how to play nicely with other packages labels Aug 12, 2022
@Zac-HD
Copy link
Member Author

Zac-HD commented Aug 12, 2022

This seems to be an upstream bug where inspect.getsource() will usually fail with OSError (which is fine), but sometimes just return a bug chunk of source code from somewhere else. Which doesn't work so well.

I'm just going to install a quick workaround and move on for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something is clearly wrong here interop how to play nicely with other packages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant