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

Clarify "What exactly are you trying to pull?" #59

Closed
habnabit opened this issue Aug 8, 2016 · 3 comments
Closed

Clarify "What exactly are you trying to pull?" #59

habnabit opened this issue Aug 8, 2016 · 3 comments

Comments

@habnabit
Copy link

habnabit commented Aug 8, 2016

toml/toml.py

Lines 61 to 62 in df2b2df

if not isinstance(s, basestring):
raise TypeError("What exactly are you trying to pull?")

    if not isinstance(s, basestring):
        raise TypeError("What exactly are you trying to pull?")

It's not a very useful error message if you have to dig into the source to figure out what it means. In this case, a bytes was being passed in, which is not permissible in python 3. Better would be to avoid basestring at all, as it is basically nonsense. Check for bytes or unicode and encode or decode appropriately.

@uiri
Copy link
Owner

uiri commented Oct 28, 2016

Any suggestions on what a better error message would be?

    if not isinstance(s, basestring):
        raise TypeError("Expecting something like a string")

Would this be better?

@habnabit
Copy link
Author

I'd recommend isinstance(s, unicode) and deleting the utf-8 decode attempt, but sure, that message at least conveys some meaning. With the fixes suggested, perhaps:

    if not isinstance(s, unicode):
        raise TypeError('expected {!r} to be unicode; got {!r}'.format(s, type(s)))

@uiri
Copy link
Owner

uiri commented Oct 28, 2016

I'd recommend isinstance(s, unicode) and deleting the utf-8 decode attempt, but sure, that message at least conveys some meaning.

The code is meant to run on both python2 and python3. For that reason, I need to keep the utf-8 decode attempt. In python3, it will only accept normal (unicode) strings. In python2, it will accept both normal strings and unicode strings. When running on python3, basestring is equal to str.

With that in mind, the error message should make sense on both python 2 and 3.

@uiri uiri closed this as completed in dcf5c81 Nov 15, 2016
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

No branches or pull requests

2 participants