Visitar URL original
exceptions.py tests failing on >= 3.7 because repr changed · Issue #1088 · RustPython/RustPython · GitHub
Skip to content

exceptions.py tests failing on >= 3.7 because repr changed #1088

Description

@silmeth

CPython 3.7 changed exception’s repr implementation to get rid of a trailing comma:

repr for BaseException has changed to not include the trailing comma. Most exceptions are affected by this change. (Contributed by Serhiy Storchaka in bpo-30399.)

This makes the test case from exceptions.py fail on CPython 3.7 and later.

Should we get rid of the tests for repr, or perhaps just test substrings (that repr string contains both the type and the message)?

Activity

  1. added
    C-compatA discrepancy between RustPython and CPython
    on Jun 30, 2019
  2. changed the title [-]exceptions.py tests failing on > 3.7 because repr changed[/-] [+]exceptions.py tests failing on >= 3.7 because repr changed[/+] on Jun 30, 2019
  3. windelbouwman commented on Jul 7, 2019

    @windelbouwman
    Contributor

    Should we aim for python3.7 compatibility? I think removing the trailing comma is good.

    We could test for python version number in the test, but this might not be a good thing to start with. It feels like a rabbit hole.

  4. silmeth commented on Jul 7, 2019

    @silmeth
    ContributorAuthor

    I don’t think this behaviour is well documented anywhere in the official docs (or that built-in exceptions repr is documented at all, at least I cannot find it easily), so perhaps aiming at exact reproduction of any CPython’s behaviour isn’t necessary?

    I’d myself restrict the tests to checking some minimal requirements that any sane Python3 (including both CPython 3.6 and CPython 3.7) meet. Eg. that the repr string contains the exception type first and then later it contains the message – but disregard punctuation entirely. Or just check that the message is enclosed in parentheses.

    Since this is a detail that CPython changed from version to version, the client code shouldn’t rely on it anyway.

  5. silmeth commented on Jul 7, 2019

    @silmeth
    ContributorAuthor

    Or since repr should give a proper working Python representation (that would yield an object with the same value when passed to eval()) – perhaps doing a round-trip test: checking whether eval() on the repr(exception) gives the same exception would be a good solution that all good Python implementation should pass?

    EDIT: that’d need an additional util for testing exception equality, something like this might work:

    def exceptions_eq(e1, e2):
        return type(e1) is type(e2) and e1.args == e2.args
    
    assert exceptions_eq(OverflowError('a'), eval(repr(OverflowError('a'))))
  6. windelbouwman commented on Jul 7, 2019

    @windelbouwman
    Contributor

    That sounds fair. Then we can add an additional function:

    def round_trip(ex):
        assert exceptions_eq(ex, eval(repr(ex)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-compatA discrepancy between RustPython and CPython

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions