Merge pull request #9385 from jdufresne/named-temp-file

Remove unnecessary type override NamedTemporaryFileResult
This commit is contained in:
Pradyun Gedam 2020-12-28 07:36:22 +00:00 committed by GitHub
commit adca454611
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 12 deletions

View File

@ -46,6 +46,7 @@ else:
from typing import ( from typing import (
IO, IO,
Any, Any,
BinaryIO,
Callable, Callable,
Dict, Dict,
Iterable, Iterable,
@ -65,7 +66,6 @@ else:
from pip._vendor.pkg_resources import Distribution from pip._vendor.pkg_resources import Distribution
from pip._internal.models.scheme import Scheme from pip._internal.models.scheme import Scheme
from pip._internal.utils.filesystem import NamedTemporaryFileResult
RecordPath = NewType('RecordPath', str) RecordPath = NewType('RecordPath', str)
InstalledCSVRow = Tuple[RecordPath, str, Union[int, str]] InstalledCSVRow = Tuple[RecordPath, str, Union[int, str]]
@ -742,7 +742,7 @@ def _install_wheel(
@contextlib.contextmanager @contextlib.contextmanager
def _generate_file(path, **kwargs): def _generate_file(path, **kwargs):
# type: (str, **Any) -> Iterator[NamedTemporaryFileResult] # type: (str, **Any) -> Iterator[BinaryIO]
with adjacent_tmp_file(path, **kwargs) as f: with adjacent_tmp_file(path, **kwargs) as f:
yield f yield f
os.chmod(f.name, generated_file_mode) os.chmod(f.name, generated_file_mode)

View File

@ -19,12 +19,6 @@ from pip._internal.utils.typing import MYPY_CHECK_RUNNING, cast
if MYPY_CHECK_RUNNING: if MYPY_CHECK_RUNNING:
from typing import Any, BinaryIO, Iterator, List, Union from typing import Any, BinaryIO, Iterator, List, Union
class NamedTemporaryFileResult(BinaryIO):
@property
def file(self):
# type: () -> BinaryIO
pass
def check_path_owner(path): def check_path_owner(path):
# type: (str) -> bool # type: (str) -> bool
@ -86,7 +80,7 @@ def is_socket(path):
@contextmanager @contextmanager
def adjacent_tmp_file(path, **kwargs): def adjacent_tmp_file(path, **kwargs):
# type: (str, **Any) -> Iterator[NamedTemporaryFileResult] # type: (str, **Any) -> Iterator[BinaryIO]
"""Return a file-like object pointing to a tmp file next to path. """Return a file-like object pointing to a tmp file next to path.
The file is created securely and is ensured to be written to disk The file is created securely and is ensured to be written to disk
@ -102,12 +96,12 @@ def adjacent_tmp_file(path, **kwargs):
suffix='.tmp', suffix='.tmp',
**kwargs **kwargs
) as f: ) as f:
result = cast('NamedTemporaryFileResult', f) result = cast('BinaryIO', f)
try: try:
yield result yield result
finally: finally:
result.file.flush() result.flush()
os.fsync(result.file.fileno()) os.fsync(result.fileno())
_replace_retry = retry(stop_max_delay=1000, wait_fixed=250) _replace_retry = retry(stop_max_delay=1000, wait_fixed=250)