Skip to content

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

@mgorny

Description

@mgorny

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"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleIssues without activity for more than 60 days

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions