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

Avoid DeprecationWarning from urllib3 #719

Merged
merged 4 commits into from Nov 29, 2020

Conversation

bhrutledge
Copy link
Contributor

When running tests, I've started to see:

=============================== warnings summary ===============================
tests/test_repository.py: 44 warnings
  /Users/brian/Code/twine/venv/lib/python3.6/site-packages/urllib3/util/retry.py:255: DeprecationWarning: Using 'method_whitelist' with Retry is deprecated and will be removed in v2.0. Use 'allowed_methods' instead
    DeprecationWarning,

-- Docs: https://docs.pytest.org/en/stable/warnings.html

For details, see:

This is an attempt to silence that warning, while remaining flexible on the version of urllib3. I'm guessing there are other (possibly preferable) approaches. For example, we could require urllib3<2, and suppress the warning.

setup.cfg Outdated Show resolved Hide resolved
twine/repository.py Outdated Show resolved Hide resolved
return adapters.HTTPAdapter(max_retries=retry)

# method_whitelist will be removed in 2.0; avoid DeprecationWarning until then
urllib3_version = importlib_metadata.version("urllib3")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please let's not check the version like this. Why not just do something simple like:

try:
    retry = urllib3.Retry(allowed_methods=["GET"], **retry_kwargs)
except TypeError:
    # NOTE remove once urllib3 1.26 is the minimum version
    retry = urllib3.Retry(method_whitelist=["GET"], **retry_kwargs)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️ This is much better, thanks. Done.


try:
retry = urllib3.Retry(allowed_methods=["GET"], **retry_kwargs)
except TypeError: # pragma: no cover
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this locally, via b07f7db. But -e py36 isn't run by the GitHub Action; instead, it runs -e py to use the job's matrix.python version:

matrix:
python: [3.6, 3.7, 3.8, 3.9]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install dependencies
run: python -m pip install tox
- name: Run tests
run: python -m tox -e py -- --cov-report xml

With that in mind, this felt like a reasonable time to use no cover.

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

Successfully merging this pull request may close these issues.

None yet

2 participants