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

hashlib requires the buffer protocol, which symbolics bytes don't provide #272

Closed
Zac-HD opened this issue Jul 13, 2024 · 1 comment
Closed

Comments

@Zac-HD
Copy link
Contributor

Zac-HD commented Jul 13, 2024

import hashlib
from crosshair.core_and_libs import proxy_for_type, standalone_statespace

with standalone_statespace:
    buf = proxy_for_type(bytes, "buf")
    hashlib.sha256(buf)
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/crosshair/util.py", line 298, in load_file
    return import_module(module_name)
  File "/usr/local/lib/python3.10/site-packages/crosshair/util.py", line 284, in import_module
    result_module = importlib.import_module(module_name)
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/tmp/main.py", line 6, in <module>
    hashlib.sha256(buf)
TypeError: object supporting the buffer API required

(originally via HypothesisWorks/hypothesis#4034, similar to #271; I suspect I'm misusing crosshair-web because it's treating this as an import failure instead of giving me a nice repro link - lovely UX though!)

@pschanely
Copy link
Owner

pschanely commented Jul 14, 2024

Fixed in v0.0.61! (but just realizes the inputs)

Re UX, thanks - but it's just an (old) fork of mypy playground.

Yeah, so crosshar-web is really intended to run on a function with a contract, so the equivalent is something like this. But at some point Liam discovered that you could also use it to share little snippets of code. (we use standalone_statespace internally for tests a lot b/c it sets up everything you need to use symbolics, but without the path exploration loop). In this case, any error will show as an "import" error, since crosshair is attempting to import the code before getting on to the contract testing.

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

No branches or pull requests

2 participants