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

isinstance(..., str) fails when applied to elements of sys.argv #170

Open
maxalbert opened this issue Sep 22, 2015 · 1 comment
Open

isinstance(..., str) fails when applied to elements of sys.argv #170

maxalbert opened this issue Sep 22, 2015 · 1 comment

Comments

@maxalbert
Copy link

This bug is related to the issues with isinstance(..., str) described here.

The following works in Python 2.7:

from __future__ import unicode_literals
from builtins import str

assert isinstance('some string', str)

However, the following fails (also in Python 2.7):

from __future__ import unicode_literals
from builtins import str
import sys

assert isinstance(sys.argv[0], str)

The reason is that elements of sys.argv are still instances of the original type str, not of future.types.newstr.newstr. This makes working with command line arguments tricky in legacy Py2 code that is being upgraded for Py2/Py3 compatibility using python-future.

For the record, both code snippets above work as expected in Python 3.4.

@jmadler
Copy link
Contributor

jmadler commented Oct 12, 2018

Would it work to add sys.argv = [str(x) for x in sys.argv] to src/builtins/__init__.py?

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

No branches or pull requests

2 participants