Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3706ef6

Browse files
authored
Revert "gh-132947: Apply changes from importlib_metadata 8.7 (#137885)" (#137924)
This reverts commit5292fc0.
1 parent8750e5e commit3706ef6

File tree

12 files changed

+118
-290
lines changed

12 files changed

+118
-290
lines changed

‎Lib/importlib/metadata/__init__.py‎

Lines changed: 62 additions & 143 deletions
Large diffs are not rendered by default.

‎Lib/importlib/metadata/_adapters.py‎

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,11 @@
1-
importemail.message
2-
importemail.policy
31
importre
42
importtextwrap
3+
importemail.message
54

65
from ._textimportFoldedCase
76

87

9-
classRawPolicy(email.policy.EmailPolicy):
10-
deffold(self,name,value):
11-
folded=self.linesep.join(
12-
textwrap.indent(value,prefix=' '*8,predicate=lambdaline:True)
13-
.lstrip()
14-
.splitlines()
15-
)
16-
returnf'{name}:{folded}{self.linesep}'
17-
18-
198
classMessage(email.message.Message):
20-
r"""
21-
Specialized Message subclass to handle metadata naturally.
22-
23-
Reads values that may have newlines in them and converts the
24-
payload to the Description.
25-
26-
>>> msg_text = textwrap.dedent('''
27-
... Name: Foo
28-
... Version: 3.0
29-
... License: blah
30-
... de-blah
31-
... <BLANKLINE>
32-
... First line of description.
33-
... Second line of description.
34-
... <BLANKLINE>
35-
... Fourth line!
36-
... ''').lstrip().replace('<BLANKLINE>', '')
37-
>>> msg = Message(email.message_from_string(msg_text))
38-
>>> msg['Description']
39-
'First line of description.\nSecond line of description.\n\nFourth line!\n'
40-
41-
Message should render even if values contain newlines.
42-
43-
>>> print(msg)
44-
Name: Foo
45-
Version: 3.0
46-
License: blah
47-
de-blah
48-
Description: First line of description.
49-
Second line of description.
50-
<BLANKLINE>
51-
Fourth line!
52-
<BLANKLINE>
53-
<BLANKLINE>
54-
"""
55-
569
multiple_use_keys=set(
5710
map(
5811
FoldedCase,
@@ -104,20 +57,15 @@ def __getitem__(self, item):
10457
def_repair_headers(self):
10558
defredent(value):
10659
"Correct for RFC822 indentation"
107-
indent=' '*8
108-
ifnotvalueor'\n'+indentnotinvalue:
60+
ifnotvalueor'\n'notinvalue:
10961
returnvalue
110-
returntextwrap.dedent(indent+value)
62+
returntextwrap.dedent(' '*8+value)
11163

11264
headers= [(key,redent(value))forkey,valueinvars(self)['_headers']]
11365
ifself._payload:
11466
headers.append(('Description',self.get_payload()))
115-
self.set_payload('')
11667
returnheaders
11768

118-
defas_string(self):
119-
returnsuper().as_string(policy=RawPolicy())
120-
12169
@property
12270
defjson(self):
12371
"""

‎Lib/importlib/metadata/_collections.py‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
importcollections
2-
importtyping
32

43

54
# from jaraco.collections 3.3
@@ -25,10 +24,7 @@ def freeze(self):
2524
self._frozen=lambdakey:self.default_factory()
2625

2726

28-
classPair(typing.NamedTuple):
29-
name:str
30-
value:str
31-
27+
classPair(collections.namedtuple('Pair','name value')):
3228
@classmethod
3329
defparse(cls,text):
3430
returncls(*map(str.strip,text.split("=",1)))

‎Lib/importlib/metadata/_functools.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
importfunctools
21
importtypes
2+
importfunctools
33

44

55
# from jaraco.functools 3.3

‎Lib/importlib/metadata/_meta.py‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
from __future__importannotations
22

33
importos
4-
fromcollections.abcimportIterator
5-
fromtypingimport (
6-
Any,
7-
Protocol,
8-
TypeVar,
9-
overload,
10-
)
4+
fromtypingimportProtocol
5+
fromtypingimportAny,Dict,Iterator,List,Optional,TypeVar,Union,overload
6+
117

128
_T=TypeVar("_T")
139

@@ -24,25 +20,25 @@ def __iter__(self) -> Iterator[str]: ... # pragma: no cover
2420
@overload
2521
defget(
2622
self,name:str,failobj:None=None
27-
)->str|None: ...# pragma: no cover
23+
)->Optional[str]: ...# pragma: no cover
2824

2925
@overload
30-
defget(self,name:str,failobj:_T)->str|_T: ...# pragma: no cover
26+
defget(self,name:str,failobj:_T)->Union[str,_T]: ...# pragma: no cover
3127

3228
# overload per python/importlib_metadata#435
3329
@overload
3430
defget_all(
3531
self,name:str,failobj:None=None
36-
)->list[Any]|None: ...# pragma: no cover
32+
)->Optional[List[Any]]: ...# pragma: no cover
3733

3834
@overload
39-
defget_all(self,name:str,failobj:_T)->list[Any]|_T:
35+
defget_all(self,name:str,failobj:_T)->Union[List[Any],_T]:
4036
"""
4137
Return all values associated with a possibly multi-valued key.
4238
"""
4339

4440
@property
45-
defjson(self)->dict[str,str|list[str]]:
41+
defjson(self)->Dict[str,Union[str,List[str]]]:
4642
"""
4743
A JSON-compatible form of the metadata.
4844
"""
@@ -54,11 +50,11 @@ class SimplePath(Protocol):
5450
"""
5551

5652
defjoinpath(
57-
self,other:str|os.PathLike[str]
53+
self,other:Union[str,os.PathLike[str]]
5854
)->SimplePath: ...# pragma: no cover
5955

6056
def__truediv__(
61-
self,other:str|os.PathLike[str]
57+
self,other:Union[str,os.PathLike[str]]
6258
)->SimplePath: ...# pragma: no cover
6359

6460
@property

‎Lib/importlib/metadata/_typing.py‎

Lines changed: 0 additions & 15 deletions
This file was deleted.

‎Lib/test/test_importlib/metadata/_path.py‎

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
# from jaraco.path 3.7.2
2-
3-
from __future__importannotations
1+
# from jaraco.path 3.7
42

53
importfunctools
64
importpathlib
7-
fromcollections.abcimportMapping
8-
fromtypingimportTYPE_CHECKING,Protocol,Union,runtime_checkable
9-
10-
ifTYPE_CHECKING:
11-
fromtyping_extensionsimportSelf
5+
fromtypingimportDict,Protocol,Union
6+
fromtypingimportruntime_checkable
127

138

149
classSymlink(str):
@@ -17,25 +12,29 @@ class Symlink(str):
1712
"""
1813

1914

20-
FilesSpec=Mapping[str,Union[str,bytes,Symlink,'FilesSpec']]
15+
FilesSpec=Dict[str,Union[str,bytes,Symlink,'FilesSpec']]# type: ignore
2116

2217

2318
@runtime_checkable
2419
classTreeMaker(Protocol):
25-
def__truediv__(self,other,/)->Self: ...
26-
defmkdir(self,*,exist_ok)->object: ...
27-
defwrite_text(self,content,/,*,encoding)->object: ...
28-
defwrite_bytes(self,content,/)->object: ...
29-
defsymlink_to(self,target,/)->object: ...
20+
def__truediv__(self,*args,**kwargs): ...# pragma: no cover
21+
22+
defmkdir(self,**kwargs): ...# pragma: no cover
23+
24+
defwrite_text(self,content,**kwargs): ...# pragma: no cover
25+
26+
defwrite_bytes(self,content): ...# pragma: no cover
27+
28+
defsymlink_to(self,target): ...# pragma: no cover
3029

3130

32-
def_ensure_tree_maker(obj:str|TreeMaker)->TreeMaker:
33-
returnobjifisinstance(obj,TreeMaker)elsepathlib.Path(obj)
31+
def_ensure_tree_maker(obj:Union[str,TreeMaker])->TreeMaker:
32+
returnobjifisinstance(obj,TreeMaker)elsepathlib.Path(obj)# type: ignore
3433

3534

3635
defbuild(
3736
spec:FilesSpec,
38-
prefix:str|TreeMaker=pathlib.Path(),
37+
prefix:Union[str,TreeMaker]=pathlib.Path(),# type: ignore
3938
):
4039
"""
4140
Build a set of files/directories, as described by the spec.
@@ -67,24 +66,23 @@ def build(
6766

6867

6968
@functools.singledispatch
70-
defcreate(content:str|bytes|FilesSpec,path:TreeMaker)->None:
69+
defcreate(content:Union[str,bytes,FilesSpec],path):
7170
path.mkdir(exist_ok=True)
72-
# Mypy only looks at the signature of the main singledispatch method. So it must contain the complete Union
73-
build(content,prefix=path)# type: ignore[arg-type] # python/mypy#11727
71+
build(content,prefix=path)# type: ignore
7472

7573

7674
@create.register
77-
def_(content:bytes,path:TreeMaker)->None:
75+
def_(content:bytes,path):
7876
path.write_bytes(content)
7977

8078

8179
@create.register
82-
def_(content:str,path:TreeMaker)->None:
80+
def_(content:str,path):
8381
path.write_text(content,encoding='utf-8')
8482

8583

8684
@create.register
87-
def_(content:Symlink,path:TreeMaker)->None:
85+
def_(content:Symlink,path):
8886
path.symlink_to(content)
8987

9088

‎Lib/test/test_importlib/metadata/fixtures.py‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
importcontextlib
1+
importsys
22
importcopy
3-
importfunctools
43
importjson
5-
importpathlib
64
importshutil
7-
importsys
5+
importpathlib
86
importtextwrap
7+
importfunctools
8+
importcontextlib
99

1010
fromtest.supportimportimport_helper
1111
fromtest.supportimportos_helper
@@ -14,10 +14,14 @@
1414
from .import_path
1515
from ._pathimportFilesSpec
1616

17-
ifsys.version_info>= (3,9):
18-
fromimportlibimportresources
19-
else:
20-
importimportlib_resourcesasresources
17+
18+
try:
19+
fromimportlibimportresources# type: ignore
20+
21+
getattr(resources,'files')
22+
getattr(resources,'as_file')
23+
except (ImportError,AttributeError):
24+
importimportlib_resourcesasresources# type: ignore
2125

2226

2327
@contextlib.contextmanager

‎Lib/test/test_importlib/metadata/test_api.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
importimportlib
21
importre
32
importtextwrap
43
importunittest
4+
importimportlib
55

6+
from .importfixtures
67
fromimportlib.metadataimport (
78
Distribution,
89
PackageNotFoundError,
@@ -14,8 +15,6 @@
1415
version,
1516
)
1617

17-
from .importfixtures
18-
1918

2019
classAPITests(
2120
fixtures.EggInfoPkg,

‎Lib/test/test_importlib/metadata/test_main.py‎

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
importimportlib
2-
importpickle
31
importre
2+
importpickle
43
importunittest
4+
importimportlib
5+
importimportlib.metadata
56
fromtest.supportimportos_helper
67

78
try:
89
importpyfakefs.fake_filesystem_unittestasffs
910
exceptImportError:
1011
from .stubsimportfake_filesystem_unittestasffs
1112

13+
from .importfixtures
14+
from ._pathimportSymlink
1215
fromimportlib.metadataimport (
1316
Distribution,
1417
EntryPoint,
@@ -21,9 +24,6 @@
2124
version,
2225
)
2326

24-
from .importfixtures
25-
from ._pathimportSymlink
26-
2727

2828
classBasicTests(fixtures.DistInfoPkg,unittest.TestCase):
2929
version_pattern=r'\d+\.\d+(\.\d)?'
@@ -157,16 +157,6 @@ def test_valid_dists_preferred(self):
157157
dist=Distribution.from_name('foo')
158158
assertdist.version=="1.0"
159159

160-
deftest_missing_metadata(self):
161-
"""
162-
Dists with a missing metadata file should return None.
163-
164-
Ref python/importlib_metadata#493.
165-
"""
166-
fixtures.build_files(self.make_pkg('foo-4.3',files={}),self.site_dir)
167-
assertDistribution.from_name('foo').metadataisNone
168-
assertmetadata('foo')isNone
169-
170160

171161
classNonASCIITests(fixtures.OnSysPath,fixtures.SiteDir,unittest.TestCase):
172162
@staticmethod

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp