22
22
import sys
23
23
import textwrap
24
24
import types
25
+ from collections .abc import Iterable , Mapping
25
26
from contextlib import suppress
26
27
from importlib import import_module
27
28
from importlib .abc import MetaPathFinder
28
29
from itertools import starmap
29
- from typing import Any , Iterable , List , Mapping , Match , Optional , Set , cast
30
+ from re import Match
31
+ from typing import Any , List , Optional , Set , cast
30
32
31
33
from . import _meta
32
34
from ._collections import FreezableDefaultDict , Pair
@@ -175,7 +177,7 @@ class EntryPoint:
175
177
value : str
176
178
group : str
177
179
178
- dist : Optional [ Distribution ] = None
180
+ dist : Distribution | None = None
179
181
180
182
def __init__ (self , name : str , value : str , group : str ) -> None :
181
183
vars (self ).update (name = name , value = value , group = group )
@@ -203,7 +205,7 @@ def attr(self) -> str:
203
205
return match .group ('attr' )
204
206
205
207
@property
206
- def extras (self ) -> List [str ]:
208
+ def extras (self ) -> list [str ]:
207
209
match = self .pattern .match (self .value )
208
210
assert match is not None
209
211
return re .findall (r'\w+' , match .group ('extras' ) or '' )
@@ -305,14 +307,14 @@ def select(self, **params) -> EntryPoints:
305
307
return EntryPoints (ep for ep in self if py39 .ep_matches (ep , ** params ))
306
308
307
309
@property
308
- def names (self ) -> Set [str ]:
310
+ def names (self ) -> set [str ]:
309
311
"""
310
312
Return the set of all names of all entry points.
311
313
"""
312
314
return {ep .name for ep in self }
313
315
314
316
@property
315
- def groups (self ) -> Set [str ]:
317
+ def groups (self ) -> set [str ]:
316
318
"""
317
319
Return the set of all groups of all entry points.
318
320
"""
@@ -333,7 +335,7 @@ def _from_text(text):
333
335
class PackagePath (pathlib .PurePosixPath ):
334
336
"""A reference to a path in a package"""
335
337
336
- hash : Optional [ FileHash ]
338
+ hash : FileHash | None
337
339
size : int
338
340
dist : Distribution
339
341
@@ -368,7 +370,7 @@ class Distribution(metaclass=abc.ABCMeta):
368
370
"""
369
371
370
372
@abc .abstractmethod
371
- def read_text (self , filename ) -> Optional [ str ] :
373
+ def read_text (self , filename ) -> str | None :
372
374
"""Attempt to load metadata file given by the name.
373
375
374
376
Python distribution metadata is organized by blobs of text
@@ -428,7 +430,7 @@ def from_name(cls, name: str) -> Distribution:
428
430
429
431
@classmethod
430
432
def discover (
431
- cls , * , context : Optional [ DistributionFinder .Context ] = None , ** kwargs
433
+ cls , * , context : DistributionFinder .Context | None = None , ** kwargs
432
434
) -> Iterable [Distribution ]:
433
435
"""Return an iterable of Distribution objects for all packages.
434
436
@@ -524,7 +526,7 @@ def entry_points(self) -> EntryPoints:
524
526
return EntryPoints ._from_text_for (self .read_text ('entry_points.txt' ), self )
525
527
526
528
@property
527
- def files (self ) -> Optional [ List [ PackagePath ]] :
529
+ def files (self ) -> list [ PackagePath ] | None :
528
530
"""Files in this distribution.
529
531
530
532
:return: List of PackagePath for this distribution or None
@@ -616,7 +618,7 @@ def _read_files_egginfo_sources(self):
616
618
return text and map ('"{}"' .format , text .splitlines ())
617
619
618
620
@property
619
- def requires (self ) -> Optional [ List [ str ]] :
621
+ def requires (self ) -> list [ str ] | None :
620
622
"""Generated requirements specified for this Distribution"""
621
623
reqs = self ._read_dist_info_reqs () or self ._read_egg_info_reqs ()
622
624
return reqs and list (reqs )
@@ -722,7 +724,7 @@ def __init__(self, **kwargs):
722
724
vars (self ).update (kwargs )
723
725
724
726
@property
725
- def path (self ) -> List [str ]:
727
+ def path (self ) -> list [str ]:
726
728
"""
727
729
The sequence of directory path that a distribution finder
728
730
should search.
@@ -874,7 +876,7 @@ class Prepared:
874
876
normalized = None
875
877
legacy_normalized = None
876
878
877
- def __init__ (self , name : Optional [ str ] ):
879
+ def __init__ (self , name : str | None ):
878
880
self .name = name
879
881
if name is None :
880
882
return
@@ -944,7 +946,7 @@ def __init__(self, path: SimplePath) -> None:
944
946
"""
945
947
self ._path = path
946
948
947
- def read_text (self , filename : str | os .PathLike [str ]) -> Optional [ str ] :
949
+ def read_text (self , filename : str | os .PathLike [str ]) -> str | None :
948
950
with suppress (
949
951
FileNotFoundError ,
950
952
IsADirectoryError ,
@@ -1051,7 +1053,7 @@ def entry_points(**params) -> EntryPoints:
1051
1053
return EntryPoints (eps ).select (** params )
1052
1054
1053
1055
1054
- def files (distribution_name : str ) -> Optional [ List [ PackagePath ]] :
1056
+ def files (distribution_name : str ) -> list [ PackagePath ] | None :
1055
1057
"""Return a list of files for the named package.
1056
1058
1057
1059
:param distribution_name: The name of the distribution package to query.
@@ -1060,7 +1062,7 @@ def files(distribution_name: str) -> Optional[List[PackagePath]]:
1060
1062
return distribution (distribution_name ).files
1061
1063
1062
1064
1063
- def requires (distribution_name : str ) -> Optional [ List [ str ]] :
1065
+ def requires (distribution_name : str ) -> list [ str ] | None :
1064
1066
"""
1065
1067
Return a list of requirements for the named package.
1066
1068
@@ -1070,7 +1072,7 @@ def requires(distribution_name: str) -> Optional[List[str]]:
1070
1072
return distribution (distribution_name ).requires
1071
1073
1072
1074
1073
- def packages_distributions () -> Mapping [str , List [str ]]:
1075
+ def packages_distributions () -> Mapping [str , list [str ]]:
1074
1076
"""
1075
1077
Return a mapping of top-level packages to their
1076
1078
distributions.
@@ -1091,7 +1093,7 @@ def _top_level_declared(dist):
1091
1093
return (dist .read_text ('top_level.txt' ) or '' ).split ()
1092
1094
1093
1095
1094
- def _topmost (name : PackagePath ) -> Optional [ str ] :
1096
+ def _topmost (name : PackagePath ) -> str | None :
1095
1097
"""
1096
1098
Return the top-most parent as long as there is a parent.
1097
1099
"""
0 commit comments