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

Function istext sometimes gives wrong results #154

Open
ghost opened this issue Jun 27, 2015 · 1 comment
Open

Function istext sometimes gives wrong results #154

ghost opened this issue Jun 27, 2015 · 1 comment

Comments

@ghost
Copy link

ghost commented Jun 27, 2015

In a specific setup (did not have time to investigate the root cause or come up with a minimal example, in my specific case it happens in the json module that tries to sort keys) I end up with a list of objects (all strings), but of different types that the istext function wrongly reports to be not of text type.

It raises the following exceptions in the compare methods (__lt__, ...) because istext returns False:

exceptions.TypeError: ("unorderable types: str() and <type 'str'>",)

This can be fixed by changing the check in the (deprecated) method istext in utils/__init__.py to

return isinstance(obj, type(u'')) or isinstance(obj, str)

@azmeuk
Copy link
Contributor

azmeuk commented Mar 6, 2017

I could reproduce this with python2:

>>> from builtins import str
>>> "" < str("")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../env/lib/python2.7/site-packages/future/types/newstr.py", line 316, in __gt__
    raise TypeError(self.unorderable_err.format(type(other)))
TypeError: unorderable types: str() and <type 'str'>

It raises an exception with b"" < str("") too, but not with u"" < str("").

I do not know if it is a bug or a feature since it seems to be the expected behavior in the tests.

However, I would expect this to work, because without importing str from builtins, "" < str("") works with python 2 and python 3.

@edschofield Do you have a thought on this? Would you be OK for pull requests fixing this behavior?

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

1 participant