2222import sys
2323import textwrap
2424import types
25+ from collections .abc import Iterable , Mapping
2526from contextlib import suppress
2627from importlib import import_module
2728from importlib .abc import MetaPathFinder
2829from 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
3032
3133from . import _meta
3234from ._collections import FreezableDefaultDict , Pair
@@ -175,7 +177,7 @@ class EntryPoint:
175177 value : str
176178 group : str
177179
178- dist : Optional [ Distribution ] = None
180+ dist : Distribution | None = None
179181
180182 def __init__ (self , name : str , value : str , group : str ) -> None :
181183 vars (self ).update (name = name , value = value , group = group )
@@ -203,7 +205,7 @@ def attr(self) -> str:
203205 return match .group ('attr' )
204206
205207 @property
206- def extras (self ) -> List [str ]:
208+ def extras (self ) -> list [str ]:
207209 match = self .pattern .match (self .value )
208210 assert match is not None
209211 return re .findall (r'\w+' , match .group ('extras' ) or '' )
@@ -305,14 +307,14 @@ def select(self, **params) -> EntryPoints:
305307 return EntryPoints (ep for ep in self if py39 .ep_matches (ep , ** params ))
306308
307309 @property
308- def names (self ) -> Set [str ]:
310+ def names (self ) -> set [str ]:
309311 """
310312 Return the set of all names of all entry points.
311313 """
312314 return {ep .name for ep in self }
313315
314316 @property
315- def groups (self ) -> Set [str ]:
317+ def groups (self ) -> set [str ]:
316318 """
317319 Return the set of all groups of all entry points.
318320 """
@@ -333,7 +335,7 @@ def _from_text(text):
333335class PackagePath (pathlib .PurePosixPath ):
334336 """A reference to a path in a package"""
335337
336- hash : Optional [ FileHash ]
338+ hash : FileHash | None
337339 size : int
338340 dist : Distribution
339341
@@ -368,7 +370,7 @@ class Distribution(metaclass=abc.ABCMeta):
368370 """
369371
370372 @abc .abstractmethod
371- def read_text (self , filename ) -> Optional [ str ] :
373+ def read_text (self , filename ) -> str | None :
372374 """Attempt to load metadata file given by the name.
373375
374376 Python distribution metadata is organized by blobs of text
@@ -428,7 +430,7 @@ def from_name(cls, name: str) -> Distribution:
428430
429431 @classmethod
430432 def discover (
431- cls , * , context : Optional [ DistributionFinder .Context ] = None , ** kwargs
433+ cls , * , context : DistributionFinder .Context | None = None , ** kwargs
432434 ) -> Iterable [Distribution ]:
433435 """Return an iterable of Distribution objects for all packages.
434436
@@ -524,7 +526,7 @@ def entry_points(self) -> EntryPoints:
524526 return EntryPoints ._from_text_for (self .read_text ('entry_points.txt' ), self )
525527
526528 @property
527- def files (self ) -> Optional [ List [ PackagePath ]] :
529+ def files (self ) -> list [ PackagePath ] | None :
528530 """Files in this distribution.
529531
530532 :return: List of PackagePath for this distribution or None
@@ -616,7 +618,7 @@ def _read_files_egginfo_sources(self):
616618 return text and map ('"{}"' .format , text .splitlines ())
617619
618620 @property
619- def requires (self ) -> Optional [ List [ str ]] :
621+ def requires (self ) -> list [ str ] | None :
620622 """Generated requirements specified for this Distribution"""
621623 reqs = self ._read_dist_info_reqs () or self ._read_egg_info_reqs ()
622624 return reqs and list (reqs )
@@ -722,7 +724,7 @@ def __init__(self, **kwargs):
722724 vars (self ).update (kwargs )
723725
724726 @property
725- def path (self ) -> List [str ]:
727+ def path (self ) -> list [str ]:
726728 """
727729 The sequence of directory path that a distribution finder
728730 should search.
@@ -874,7 +876,7 @@ class Prepared:
874876 normalized = None
875877 legacy_normalized = None
876878
877- def __init__ (self , name : Optional [ str ] ):
879+ def __init__ (self , name : str | None ):
878880 self .name = name
879881 if name is None :
880882 return
@@ -944,7 +946,7 @@ def __init__(self, path: SimplePath) -> None:
944946 """
945947 self ._path = path
946948
947- def read_text (self , filename : str | os .PathLike [str ]) -> Optional [ str ] :
949+ def read_text (self , filename : str | os .PathLike [str ]) -> str | None :
948950 with suppress (
949951 FileNotFoundError ,
950952 IsADirectoryError ,
@@ -1051,7 +1053,7 @@ def entry_points(**params) -> EntryPoints:
10511053 return EntryPoints (eps ).select (** params )
10521054
10531055
1054- def files (distribution_name : str ) -> Optional [ List [ PackagePath ]] :
1056+ def files (distribution_name : str ) -> list [ PackagePath ] | None :
10551057 """Return a list of files for the named package.
10561058
10571059 :param distribution_name: The name of the distribution package to query.
@@ -1060,7 +1062,7 @@ def files(distribution_name: str) -> Optional[List[PackagePath]]:
10601062 return distribution (distribution_name ).files
10611063
10621064
1063- def requires (distribution_name : str ) -> Optional [ List [ str ]] :
1065+ def requires (distribution_name : str ) -> list [ str ] | None :
10641066 """
10651067 Return a list of requirements for the named package.
10661068
@@ -1070,7 +1072,7 @@ def requires(distribution_name: str) -> Optional[List[str]]:
10701072 return distribution (distribution_name ).requires
10711073
10721074
1073- def packages_distributions () -> Mapping [str , List [str ]]:
1075+ def packages_distributions () -> Mapping [str , list [str ]]:
10741076 """
10751077 Return a mapping of top-level packages to their
10761078 distributions.
@@ -1091,7 +1093,7 @@ def _top_level_declared(dist):
10911093 return (dist .read_text ('top_level.txt' ) or '' ).split ()
10921094
10931095
1094- def _topmost (name : PackagePath ) -> Optional [ str ] :
1096+ def _topmost (name : PackagePath ) -> str | None :
10951097 """
10961098 Return the top-most parent as long as there is a parent.
10971099 """
0 commit comments