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

Revert back piptools._compat.contextlib #1338

Merged
merged 2 commits into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions piptools/_compat/contextlib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Ported from python 3.7 contextlib.py
from types import TracebackType
from typing import Optional, Type, TypeVar

_T = TypeVar("_T")


class nullcontext:
"""Context manager that does no additional processing.
Used as a stand-in for a normal context manager, when a particular
block of code is only sometimes used with a normal context manager:
cm = optional_cm if condition else nullcontext()
with cm:
# Perform operation, using optional_cm if condition is True

TODO: replace with `contextlib.nullcontext()` after Python 3.6 being dropped
"""

def __init__(self, enter_result: Optional[_T] = None) -> None:
self.enter_result = enter_result

def __enter__(self) -> Optional[_T]:
return self.enter_result

def __exit__(
self,
exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType],
) -> Optional[bool]:
pass
5 changes: 2 additions & 3 deletions piptools/repositories/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
from pip._internal.utils.misc import normalize_path
from pip._internal.utils.temp_dir import TempDirectory, global_tempdir_manager
from pip._internal.utils.urls import path_to_url, url_to_path
from pip._vendor import contextlib2
from pip._vendor.requests import RequestException

from .._compat import PIP_VERSION
from .._compat import PIP_VERSION, contextlib
from ..exceptions import NoCandidateFound
from ..logging import log
from ..utils import (
Expand Down Expand Up @@ -407,7 +406,7 @@ def _get_file_hash(self, link):
width=32,
)
else:
context_manager = contextlib2.nullcontext(chunks)
context_manager = contextlib.nullcontext(chunks)

# Iterate over the chosen context manager
with context_manager as bar:
Expand Down