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

prevent unnessary b' prefix in parse_isodate exception messages #1122

Merged
merged 1 commit into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ switch, and thus all their contributions are dual-licensed.
- Nicolas Évrard (gh: @nicoe) **D**
- Nick Smith <nick.smith@MASKED>
- Orson Adams <orson.network@MASKED> (gh: @parsethis) **D**
- Paul Brown (gh: @pawl) **D**
- Paul Dickson (gh @prdickson) **D**
- Paul Ganssle <paul@ganssle.io> (gh: @pganssle) **R**
- Pascal van Kooten <kootenpv@MASKED> (gh: @kootenpv) **R**
Expand Down
1 change: 1 addition & 0 deletions changelog.d/1122.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a bug that caused b' prefixes to appear in parse_isodate exception messages.
2 changes: 1 addition & 1 deletion dateutil/parser/isoparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def parse_isodate(self, datestr):
components, pos = self._parse_isodate(datestr)
if pos < len(datestr):
raise ValueError('String contains unknown ISO ' +
'components: {}'.format(datestr))
'components: {!r}'.format(datestr.decode('ascii')))
return date(*components)

@_takes_ascii
Expand Down
12 changes: 12 additions & 0 deletions dateutil/test/test_isoparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,18 @@ def test_isodate_raises(isostr, exception):
isoparser().parse_isodate(isostr)


def test_parse_isodate_error_text():
with pytest.raises(ValueError) as excinfo:
isoparser().parse_isodate('2014-0423')

# ensure the error message does not contain b' prefixes
if six.PY2:
expected_error = "String contains unknown ISO components: u'2014-0423'"
else:
expected_error = "String contains unknown ISO components: '2014-0423'"
assert expected_error == str(excinfo.value)


###
# Test parse_isotime
def __make_time_examples():
Expand Down