Skip to content

pkg_resources' detection of Python2 vs Python3 is brittle #237

@ghost

Description

Originally reported by: anntzer (Bitbucket: anntzer, GitHub: anntzer)


The following part of pkg_resources

#!python
try:
    basestring
    next = lambda o: o.next()
    from cStringIO import StringIO as BytesIO
except NameError:
    basestring = str
    from io import BytesIO
    def execfile(fn, globs=None, locs=None):
        if globs is None:
            globs = globals()
        if locs is None:
            locs = globs
        exec(compile(open(fn).read(), fn, 'exec'), globs, locs)

tries to provide some standard Python2 functions when run with Python3, but is broken if other packages already do the same, but for a different subset. Specifically, if another package already defined (in Python3) builtins.basestring = str, the import of cStringIO will fail with an ImportError, and later calls to next will fail too.


Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions