Skip to content

Unexpected behaviour of check50.Mismatch for non-string arguments #185

@mjdv

Description

@mjdv

When trying to raise Mismatch exceptions for non-string arguments, the first and last character of the string representation of the value are truncated, occasionally resulting in very cryptic error messages. Here are some examples.

>>> import check50
>>> raise check50.Mismatch(True, False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
check50._api.Mismatch: expected "ru", not "als"
>>> raise check50.Mismatch([], "")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
check50._api.Mismatch: expected "", not ""
>>> raise check50.Mismatch(10, 20)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
check50._api.Mismatch: expected "", not ""

If the Mismatch exception class only allows string arguments, I believe this should explicitly be documented.

Additionally, while testing I ran into the following (related?) issue: once a Mismatch object has been created (but not raised), raising another Mismatch object causes a different (presumably unintended) exception.

>>> import check50
>>> check50.Mismatch("foo", "bar")
Mismatch('foo', 'bar')
>>> raise check50.Mismatch("baz", "lud")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mees/.local/lib/python3.6/site-packages/check50/_api.py", line 405, in __init__
    super().__init__(rationale=_("expected {}, not {}").format(_raw(expected), _raw(actual)), help=help)
TypeError: 'Mismatch' object is not callable

Metadata

Metadata

Assignees

Labels

4.xIssues relating to check50 4.xenhancement

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions