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

pypy3 regression: tests/test_api_jws.py::TestJWS::test_options_must_be_dict - ValueError: sequence of pairs expected #580

Closed
mgorny opened this issue Dec 22, 2020 · 3 comments · Fixed by #763
Labels
stale Issues without activity for more than 60 days

Comments

@mgorny
Copy link
Contributor

mgorny commented Dec 22, 2020

The 2.0.0 release introduces a regression in PyPy 3 support.

Expected Result

Tests passing with pypy3.

Actual Result

==================================================================== FAILURES =====================================================================
________________________________________________________ TestJWS.test_options_must_be_dict ________________________________________________________

self = <tests.test_api_jws.TestJWS object at 0x00007f705bc57670>, jws = <jwt.api_jws.PyJWS object at 0x00007f705bc46020>

    def test_options_must_be_dict(self, jws):
        pytest.raises(TypeError, PyJWS, options=object())
>       pytest.raises(TypeError, PyJWS, options=("something"))

tests/test_api_jws.py:86: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <jwt.api_jws.PyJWS object at 0x00007f705b5a26e8>, algorithms = None, options = 'something'

    def __init__(self, algorithms=None, options=None):
        self._algorithms = get_default_algorithms()
        self._valid_algs = (
            set(algorithms) if algorithms is not None else set(self._algorithms)
        )
    
        # Remove algorithms that aren't on the whitelist
        for key in list(self._algorithms.keys()):
            if key not in self._valid_algs:
                del self._algorithms[key]
    
        if options is None:
            options = {}
>       self.options = {**self._get_default_options(), **options}
E       ValueError: sequence of pairs expected

jwt/api_jws.py:37: ValueError
____________________________________________________ TestJWS.test_decode_options_must_be_dict _____________________________________________________

self = <tests.test_api_jws.TestJWS object at 0x00007f7059ca8bb8>, jws = <jwt.api_jws.PyJWS object at 0x00007f7059ca8758>, payload = b'hello world'

    def test_decode_options_must_be_dict(self, jws, payload):
        token = jws.encode(payload, "secret")
    
        with pytest.raises(TypeError):
            jws.decode(token, "secret", options=object())
    
        with pytest.raises(TypeError):
>           jws.decode(token, "secret", options="something")

tests/test_api_jws.py:582: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
jwt/api_jws.py:165: in decode
    decoded = self.decode_complete(jwt, key, algorithms, options, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <jwt.api_jws.PyJWS object at 0x00007f7059ca8758>
jwt = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.aGVsbG8gd29ybGQ.gEW0pdU4kxPthjtehYdhxB9mMOGajt1xCKlGGXDJ8PM', key = 'secret', algorithms = None
options = 'something', kwargs = {}

    def decode_complete(
        self,
        jwt: str,
        key: str = "",
        algorithms: List[str] = None,
        options: Dict = None,
        **kwargs,
    ) -> Dict[str, Any]:
        if options is None:
            options = {}
>       merged_options = {**self.options, **options}
E       ValueError: sequence of pairs expected

jwt/api_jws.py:138: ValueError

Reproduction Steps

tox -e pypy3-crypto

System Information

$ pypy3 -m jwt.help
{
  "cryptography": {
    "version": "3.3.1"
  },
  "implementation": {
    "name": "PyPy",
    "version": "7.3.3beta"
  },
  "platform": {
    "release": "5.10.1",
    "system": "Linux"
  },
  "pyjwt": {
    "version": "2.0.0"
  }
}
@jpadilla
Copy link
Owner

Thanks for the report. Most likely due to #555. Note that we're still not testing against pypy3 #550

@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the stale Issues without activity for more than 60 days label May 26, 2022
@mgorny
Copy link
Contributor Author

mgorny commented May 26, 2022

Still happens as of today, with PyPy3.9 7.3.9.

mgorny added a commit to mgorny/pyjwt that referenced this issue May 26, 2022
PyPy3 raises ValueError rather than TypeError when trying to combine
a dict and a str in dict unpacking.  Update the test expectations
appropriately.

Fixes jpadilla#580
auvipy added a commit that referenced this issue May 26, 2022
* Adjust expected exceptions in option merging tests for PyPy3

PyPy3 raises ValueError rather than TypeError when trying to combine
a dict and a str in dict unpacking.  Update the test expectations
appropriately.

Fixes #580

* Enable GHA testing on Python 3.11 and all PyPy3 versions

Enable testing on all Python 3 versions supported by GitHub Actions
at the moment.  While at it, fix the tox invocation for Python 3.10.

* drop pypy3.7 from tox

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Issues without activity for more than 60 days
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants