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

Fix TypeError in str(TaskwarriorError(...)) #126

Closed
wants to merge 1 commit into from

Conversation

fdcds
Copy link

@fdcds fdcds commented Jul 23, 2019

__str__ should return a string, but string.encode(...) returns bytes instead. This commit fixes it by decoding the bytes back to a string.

Fixes: #125

`__str__` should return a string, but `string.encode(...)` returns bytes instead. This commit fixes it by decoding the bytes back to a string.

Fixes: ralphbean#125
@MatthewScholefield
Copy link

@ralphbean Ping

@@ -18,4 +18,4 @@ def __unicode__(self):
)

def __str__(self):
return self.__unicode__().encode(sys.getdefaultencoding(), 'replace')
return self.__unicode__().encode(sys.getdefaultencoding(), 'replace').decode(sys.getdefaultencoding())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just briefly glancing, I’m fairly sure this is here from when we were supporting Python 2.7 where this method had to return bytes (& I believe we’ve dropped that by now).

Rather than calling __unicode__, encoding to bytes, then decoding once again, we should really probably just move the contents of __unicode__ here and delete the __unicode__ method entirely.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI - did this as part of #149

@mcrot
Copy link

mcrot commented Dec 30, 2021

Hi, I've come across this error while using another tool for syncing tasks. Has this ever been merged?

@coddingtonbear
Copy link
Collaborator

This wasn't, no, @mcrot, but given that Python 2.7 has been unsupported for quite a while now, this should probably be fixed such that we don't go through the hoops of trying to handle both __unicode__ and __str__ simultaneously. In the Python 2.x era, the __str__ method should return bytes and the __unicode__ method: text. In Python 3.x, there is no __unicode__ method, and the __str__ method should return text instead of bytes. If you would like to file a PR with those changes, though, @mcrot, I'd love to review it.

@vrusinov
Copy link
Contributor

vrusinov commented Jan 8, 2022

@coddingtonbear could you take a look at #149 - it includes this change among few other python2 cleanups. Let me know if you'd prefer to split it.

@coddingtonbear
Copy link
Collaborator

Fixed via #149! Apologies for the back-and-forth on all of this, but I believe this error is now behind us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python 3: str(TaskwarriorError(...)): TypeError: __str__ returned non-string (type bytes)
5 participants