Skip to content

Commit d9fc620

Browse files
committed
👹 Feed the hobgoblins (delint).
1 parent 7f8f40c commit d9fc620

File tree

3 files changed

+29
-30
lines changed

3 files changed

+29
-30
lines changed

‎importlib_metadata/__init__.py‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
import sys
2323
import textwrap
2424
import types
25+
from collections.abc import Iterable, Mapping
2526
from contextlib import suppress
2627
from importlib import import_module
2728
from importlib.abc import MetaPathFinder
2829
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
3032

3133
from . import _meta
3234
from ._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):
333335
class 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
"""

‎importlib_metadata/_meta.py‎

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

33
import os
4+
from collections.abc import Iterator
45
from typing import (
56
Any,
6-
Dict,
7-
Iterator,
8-
List,
9-
Optional,
107
Protocol,
118
TypeVar,
12-
Union,
139
overload,
1410
)
1511

@@ -28,25 +24,25 @@ def __iter__(self) -> Iterator[str]: ... # pragma: no cover
2824
@overload
2925
def get(
3026
self, name: str, failobj: None = None
31-
) -> Optional[str]: ... # pragma: no cover
27+
) -> str | None: ... # pragma: no cover
3228

3329
@overload
34-
def get(self, name: str, failobj: _T) -> Union[str, _T]: ... # pragma: no cover
30+
def get(self, name: str, failobj: _T) -> str | _T: ... # pragma: no cover
3531

3632
# overload per python/importlib_metadata#435
3733
@overload
3834
def get_all(
3935
self, name: str, failobj: None = None
40-
) -> Optional[List[Any]]: ... # pragma: no cover
36+
) -> list[Any] | None: ... # pragma: no cover
4137

4238
@overload
43-
def get_all(self, name: str, failobj: _T) -> Union[List[Any], _T]:
39+
def get_all(self, name: str, failobj: _T) -> list[Any] | _T:
4440
"""
4541
Return all values associated with a possibly multi-valued key.
4642
"""
4743

4844
@property
49-
def json(self) -> Dict[str, Union[str, List[str]]]:
45+
def json(self) -> dict[str, str | list[str]]:
5046
"""
5147
A JSON-compatible form of the metadata.
5248
"""
@@ -58,11 +54,11 @@ class SimplePath(Protocol):
5854
"""
5955

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

6460
def __truediv__(
65-
self, other: Union[str, os.PathLike[str]]
61+
self, other: str | os.PathLike[str]
6662
) -> SimplePath: ... # pragma: no cover
6763

6864
@property

‎tests/_path.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
import functools
66
import pathlib
7-
from typing import TYPE_CHECKING, Mapping, Protocol, Union, runtime_checkable
7+
from collections.abc import Mapping
8+
from typing import TYPE_CHECKING, Protocol, Union, runtime_checkable
89

910
if TYPE_CHECKING:
1011
from typing_extensions import Self

0 commit comments

Comments
 (0)