Skip to content

Commit 502d08c

Browse files
committed
Remove even moar legacy Python 3.8 code
1 parent bc28953 commit 502d08c

File tree

4 files changed

+15
-42
lines changed

4 files changed

+15
-42
lines changed

src/pip/_internal/commands/search.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import xmlrpc.client
66
from collections import OrderedDict
77
from optparse import Values
8-
from typing import TYPE_CHECKING, Dict, List, Optional, TypedDict
8+
from typing import Dict, List, Optional, TypedDict
99

1010
from pip._vendor.packaging.version import parse as parse_version
1111

@@ -19,12 +19,11 @@
1919
from pip._internal.utils.logging import indent_log
2020
from pip._internal.utils.misc import write_output
2121

22-
if TYPE_CHECKING:
2322

24-
class TransformedHit(TypedDict):
25-
name: str
26-
summary: str
27-
versions: List[str]
23+
class TransformedHit(TypedDict):
24+
name: str
25+
summary: str
26+
versions: List[str]
2827

2928

3029
logger = logging.getLogger(__name__)

src/pip/_internal/metadata/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@
22
import functools
33
import os
44
import sys
5-
from typing import TYPE_CHECKING, List, Optional, Type, cast
5+
from typing import List, Literal, Optional, Protocol, Type, cast
66

77
from pip._internal.utils.misc import strtobool
88

99
from .base import BaseDistribution, BaseEnvironment, FilesystemWheel, MemoryWheel, Wheel
1010

11-
if TYPE_CHECKING:
12-
from typing import Literal, Protocol
13-
else:
14-
Protocol = object
15-
1611
__all__ = [
1712
"BaseDistribution",
1813
"BaseEnvironment",

src/pip/_internal/operations/install/wheel.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
import warnings
1414
from base64 import urlsafe_b64encode
1515
from email.message import Message
16+
from io import StringIO
1617
from itertools import chain, filterfalse, starmap
1718
from typing import (
1819
IO,
19-
TYPE_CHECKING,
2020
Any,
2121
BinaryIO,
2222
Callable,
@@ -50,7 +50,7 @@
5050
from pip._internal.models.direct_url import DIRECT_URL_METADATA_NAME, DirectUrl
5151
from pip._internal.models.scheme import SCHEME_KEYS, Scheme
5252
from pip._internal.utils.filesystem import adjacent_tmp_file, replace
53-
from pip._internal.utils.misc import StreamWrapper, ensure_dir, hash_file, partition
53+
from pip._internal.utils.misc import ensure_dir, hash_file, partition
5454
from pip._internal.utils.unpacking import (
5555
current_umask,
5656
is_within_directory,
@@ -59,15 +59,14 @@
5959
)
6060
from pip._internal.utils.wheel import parse_wheel
6161

62-
if TYPE_CHECKING:
6362

64-
class File(Protocol):
65-
src_record_path: "RecordPath"
66-
dest_path: str
67-
changed: bool
63+
class File(Protocol):
64+
src_record_path: "RecordPath"
65+
dest_path: str
66+
changed: bool
6867

69-
def save(self) -> None:
70-
pass
68+
def save(self) -> None:
69+
pass
7170

7271

7372
logger = logging.getLogger(__name__)
@@ -608,9 +607,7 @@ def pyc_output_path(path: str) -> str:
608607

609608
# Compile all of the pyc files for the installed files
610609
if pycompile:
611-
with contextlib.redirect_stdout(
612-
StreamWrapper.from_stream(sys.stdout)
613-
) as stdout:
610+
with contextlib.redirect_stdout(StringIO()) as stdout:
614611
with warnings.catch_warnings():
615612
warnings.filterwarnings("ignore")
616613
for path in pyc_source_file_paths():

src/pip/_internal/utils/misc.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import urllib.parse
1212
from dataclasses import dataclass
1313
from functools import partial
14-
from io import StringIO
1514
from itertools import filterfalse, tee, zip_longest
1615
from pathlib import Path
1716
from types import FunctionType, TracebackType
@@ -26,7 +25,6 @@
2625
Mapping,
2726
Optional,
2827
Sequence,
29-
TextIO,
3028
Tuple,
3129
Type,
3230
TypeVar,
@@ -375,22 +373,6 @@ def write_output(msg: Any, *args: Any) -> None:
375373
logger.info(msg, *args)
376374

377375

378-
class StreamWrapper(StringIO):
379-
orig_stream: TextIO
380-
381-
@classmethod
382-
def from_stream(cls, orig_stream: TextIO) -> "StreamWrapper":
383-
ret = cls()
384-
ret.orig_stream = orig_stream
385-
return ret
386-
387-
# compileall.compile_dir() needs stdout.encoding to print to stdout
388-
# type ignore is because TextIOBase.encoding is writeable
389-
@property
390-
def encoding(self) -> str: # type: ignore
391-
return self.orig_stream.encoding
392-
393-
394376
# Simulates an enum
395377
def enum(*sequential: Any, **named: Any) -> Type[Any]:
396378
enums = dict(zip(sequential, range(len(sequential))), **named)

0 commit comments

Comments
 (0)