Skip to content

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

Open
@maxalbert

Description

@maxalbert

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions