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

Remove compatibility shim for bytes type #1479

Merged
merged 2 commits into from Sep 16, 2018

Conversation

Projects
None yet
3 participants
@jdufresne
Contributor

jdufresne commented Sep 14, 2018

Summary of changes

The type bytes is available on all supported Pythons. Makes the code more forward compatible with Python 3.

Pull Request Checklist

  • News fragment added in changelog.d. See documentation for details

@jdufresne jdufresne force-pushed the jdufresne:bytes branch 2 times, most recently from 847e28f to 1b87fab Sep 14, 2018

@jaraco

This looks beautiful, but could we separate the two concerns (replacing binary_type with bytes from correcting encode to decode)?

if isinstance(pattern, binary_type):
dirname = os.curdir.encode('ASCII')
if isinstance(pattern, bytes):
dirname = os.curdir.decode('ASCII')

This comment has been minimized.

@jaraco

jaraco Sep 14, 2018

Member

So while I think you're right about this change (encode->decode), it should probably be in a separate commit and maybe even a separate PR, as it's very different from the stated intention of the commit.

This comment has been minimized.

@benoit-pierre

benoit-pierre Sep 14, 2018

Member

I think this is wrong: the goal of glob is to support this usage too:

python -c 'from setuptools.glob import glob; print(glob(b"*.rst"))'

no?
in any case, this fails with this PR.

This comment has been minimized.

@benoit-pierre

benoit-pierre Sep 14, 2018

Member

On master, from setuptools directory, the results are:

[b'README.rst', b'towncrier_template.rst', b'CHANGES.rst']

This comment has been minimized.

@benoit-pierre

benoit-pierre Sep 14, 2018

Member

This is probably a good time to add some tests.

This comment has been minimized.

@benoit-pierre

benoit-pierre Sep 14, 2018

Member

It looks like the intent of the patch was to change to:

dirname = os.curdir.encode('ASCII')

This comment has been minimized.

@jdufresne

jdufresne Sep 14, 2018

Contributor

Yup! You're right. I had that wrong. It should be dirname = os.curdir.encode('ASCII'). I've corrected this in the latest revision.

if isinstance(dirname, binary_type):
dirname = binary_type(os.curdir, 'ASCII')
if isinstance(dirname, bytes):
dirname = os.curdir.decode('ASCII')

This comment has been minimized.

@jaraco

jaraco Sep 14, 2018

Member

Again, this seems like a change to do more than just replace binary_type with bytes. How did this code work before?

@jdufresne jdufresne force-pushed the jdufresne:bytes branch from 1b87fab to 40b2b0d Sep 14, 2018

@jdufresne

This comment has been minimized.

Contributor

jdufresne commented Sep 14, 2018

This is probably a good time to add some tests.

There is no behavioral change. It is a pure internal refactoring. Do you still want to see tests for this PR? Let me know. If so, I'll add them.

@benoit-pierre

This comment has been minimized.

Member

benoit-pierre commented Sep 14, 2018

Do you still want to see tests for this PR? Let me know. If so, I'll add them.

Yes, here are some simple ones to prevent future regressions:

import pytest

from setuptools.glob import glob

from .files import build_files


@pytest.mark.parametrize('tree, pattern, matches', (
    ('', b'', []),
    ('', '', []),
    ('''
     appveyor.yml
     CHANGES.rst
     LICENSE
     MANIFEST.in
     pyproject.toml
     README.rst
     setup.cfg
     setup.py
     ''', '*.rst', ('CHANGES.rst', 'README.rst')),
    ('''
     appveyor.yml
     CHANGES.rst
     LICENSE
     MANIFEST.in
     pyproject.toml
     README.rst
     setup.cfg
     setup.py
     ''', b'*.rst', (b'CHANGES.rst', b'README.rst')),
))
def test_glob(monkeypatch, tmpdir, tree, pattern, matches):
    monkeypatch.chdir(tmpdir)
    build_files({name: '' for name in tree.split()})
    assert list(sorted(glob(pattern))) == list(sorted(matches))

To be put in setuptools/tests/test_glob.py.

jdufresne added some commits Sep 14, 2018

Remove use of compatibility shim six.binary_type
The type bytes is available on all supported Pythons. Makes the code
more forward compatible with Python 3.

@jdufresne jdufresne force-pushed the jdufresne:bytes branch from 40b2b0d to 4f165ed Sep 14, 2018

@jdufresne

This comment has been minimized.

Contributor

jdufresne commented Sep 14, 2018

Thanks. I've added the suggested tests (which do fail with the mistake I temporarily had).

@jaraco jaraco merged commit 40aabe3 into pypa:master Sep 16, 2018

3 of 5 checks passed

codecov/patch 78.57% of diff hit (target 81.36%)
Details
deploy/netlify Deploy preview failed.
Details
codecov/project 81.38% (+0.01%) compared to 948b3f4
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment