Skip to content

Commit 6fb1c9b

Browse files
committed
Now the type annotations import of importlib does not use the deprecated typing alias
1 parent 180ee43 commit 6fb1c9b

File tree

5 files changed

+26
-21
lines changed

5 files changed

+26
-21
lines changed

Lib/importlib/metadata/__init__.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
from ._itertools import always_iterable, unique_everseen
2525
from ._meta import PackageMetadata, SimplePath
2626

27+
from collections.abc import Iterable, Mapping
2728
from contextlib import suppress
2829
from importlib import import_module
2930
from importlib.abc import MetaPathFinder
3031
from itertools import starmap
31-
from typing import Any, Iterable, List, Mapping, Match, Optional, Set, cast
32+
from typing import Any, Match, Optional, cast
3233

3334
__all__ = [
3435
'Distribution',
@@ -193,7 +194,7 @@ def attr(self) -> str:
193194
return match.group('attr')
194195

195196
@property
196-
def extras(self) -> List[str]:
197+
def extras(self) -> list[str]:
197198
match = self.pattern.match(self.value)
198199
assert match is not None
199200
return re.findall(r'\w+', match.group('extras') or '')
@@ -278,14 +279,14 @@ def select(self, **params) -> EntryPoints:
278279
return EntryPoints(ep for ep in self if ep.matches(**params))
279280

280281
@property
281-
def names(self) -> Set[str]:
282+
def names(self) -> set[str]:
282283
"""
283284
Return the set of all names of all entry points.
284285
"""
285286
return {ep.name for ep in self}
286287

287288
@property
288-
def groups(self) -> Set[str]:
289+
def groups(self) -> set[str]:
289290
"""
290291
Return the set of all groups of all entry points.
291292
"""
@@ -496,7 +497,7 @@ def entry_points(self) -> EntryPoints:
496497
return EntryPoints._from_text_for(self.read_text('entry_points.txt'), self)
497498

498499
@property
499-
def files(self) -> Optional[List[PackagePath]]:
500+
def files(self) -> Optional[list[PackagePath]]:
500501
"""Files in this distribution.
501502
502503
:return: List of PackagePath for this distribution or None
@@ -589,7 +590,7 @@ def _read_files_egginfo_sources(self):
589590
return text and map('"{}"'.format, text.splitlines())
590591

591592
@property
592-
def requires(self) -> Optional[List[str]]:
593+
def requires(self) -> Optional[list[str]]:
593594
"""Generated requirements specified for this Distribution"""
594595
reqs = self._read_dist_info_reqs() or self._read_egg_info_reqs()
595596
return reqs and list(reqs)
@@ -692,7 +693,7 @@ def __init__(self, **kwargs):
692693
vars(self).update(kwargs)
693694

694695
@property
695-
def path(self) -> List[str]:
696+
def path(self) -> list[str]:
696697
"""
697698
The sequence of directory path that a distribution finder
698699
should search.
@@ -1011,7 +1012,7 @@ def entry_points(**params) -> EntryPoints:
10111012
return EntryPoints(eps).select(**params)
10121013

10131014

1014-
def files(distribution_name: str) -> Optional[List[PackagePath]]:
1015+
def files(distribution_name: str) -> Optional[list[PackagePath]]:
10151016
"""Return a list of files for the named package.
10161017
10171018
:param distribution_name: The name of the distribution package to query.
@@ -1020,7 +1021,7 @@ def files(distribution_name: str) -> Optional[List[PackagePath]]:
10201021
return distribution(distribution_name).files
10211022

10221023

1023-
def requires(distribution_name: str) -> Optional[List[str]]:
1024+
def requires(distribution_name: str) -> Optional[list[str]]:
10241025
"""
10251026
Return a list of requirements for the named package.
10261027
@@ -1030,7 +1031,7 @@ def requires(distribution_name: str) -> Optional[List[str]]:
10301031
return distribution(distribution_name).requires
10311032

10321033

1033-
def packages_distributions() -> Mapping[str, List[str]]:
1034+
def packages_distributions() -> Mapping[str, list[str]]:
10341035
"""
10351036
Return a mapping of top-level packages to their
10361037
distributions.

Lib/importlib/metadata/_meta.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from __future__ import annotations
22

33
import os
4+
from collections.abc import Iterator
45
from typing import Protocol
5-
from typing import Any, Dict, Iterator, List, Optional, TypeVar, Union, overload
6+
from typing import Any, Optional, TypeVar, Union, overload
67

78

89
_T = TypeVar("_T")
@@ -29,16 +30,16 @@ def get(self, name: str, failobj: _T) -> Union[str, _T]: ... # pragma: no cover
2930
@overload
3031
def get_all(
3132
self, name: str, failobj: None = None
32-
) -> Optional[List[Any]]: ... # pragma: no cover
33+
) -> Optional[list[Any]]: ... # pragma: no cover
3334

3435
@overload
35-
def get_all(self, name: str, failobj: _T) -> Union[List[Any], _T]:
36+
def get_all(self, name: str, failobj: _T) -> Union[list[Any], _T]:
3637
"""
3738
Return all values associated with a possibly multi-valued key.
3839
"""
3940

4041
@property
41-
def json(self) -> Dict[str, Union[str, List[str]]]:
42+
def json(self) -> dict[str, Union[str, list[str]]]:
4243
"""
4344
A JSON-compatible form of the metadata.
4445
"""

Lib/importlib/resources/abc.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import itertools
44
import os
55
import pathlib
6-
from typing import Any, BinaryIO, Iterable, Iterator, NoReturn, Text, Optional
6+
from collections.abc import Iterable, Iterator
7+
from typing import Any, BinaryIO, NoReturn, Optional
78
from typing import runtime_checkable, Protocol
89
from typing import Union
910

@@ -17,7 +18,7 @@ class ResourceReader(metaclass=abc.ABCMeta):
1718
"""Abstract base class for loaders to provide resource reading support."""
1819

1920
@abc.abstractmethod
20-
def open_resource(self, resource: Text) -> BinaryIO:
21+
def open_resource(self, resource: str) -> BinaryIO:
2122
"""Return an opened, file-like object for binary reading.
2223
2324
The 'resource' argument is expected to represent only a file name.
@@ -29,7 +30,7 @@ def open_resource(self, resource: Text) -> BinaryIO:
2930
raise FileNotFoundError
3031

3132
@abc.abstractmethod
32-
def resource_path(self, resource: Text) -> Text:
33+
def resource_path(self, resource: str) -> str:
3334
"""Return the file system path to the specified resource.
3435
3536
The 'resource' argument is expected to represent only a file name.
@@ -42,7 +43,7 @@ def resource_path(self, resource: Text) -> Text:
4243
raise FileNotFoundError
4344

4445
@abc.abstractmethod
45-
def is_resource(self, path: Text) -> bool:
46+
def is_resource(self, path: str) -> bool:
4647
"""Return True if the named 'path' is a resource.
4748
4849
Files are resources, directories are not.

Lib/importlib/resources/simple.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import abc
66
import io
77
import itertools
8-
from typing import BinaryIO, List
8+
from typing import BinaryIO
99

1010
from .abc import Traversable, TraversableResources
1111

@@ -24,14 +24,14 @@ def package(self) -> str:
2424
"""
2525

2626
@abc.abstractmethod
27-
def children(self) -> List['SimpleReader']:
27+
def children(self) -> list['SimpleReader']:
2828
"""
2929
Obtain an iterable of SimpleReader for available
3030
child containers (e.g. directories).
3131
"""
3232

3333
@abc.abstractmethod
34-
def resources(self) -> List[str]:
34+
def resources(self) -> list[str]:
3535
"""
3636
Obtain available named resources for this virtual package.
3737
"""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Now the type annotations import of ``importlib`` does not use the deprecated
2+
typing alias

0 commit comments

Comments
 (0)