Skip to content

Commit c1612ec

Browse files
committed
Use type check guard for legacy annotations
1 parent 3a90a8d commit c1612ec

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

importlib_metadata/__init__.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,25 @@
3030

3131
from contextlib import suppress
3232
from importlib import import_module
33-
from importlib import metadata as _legacy
3433
from importlib.abc import MetaPathFinder
3534
from itertools import starmap
36-
from typing import Any, Iterable, List, Mapping, Match, Optional, Set, cast
35+
from typing import (
36+
TYPE_CHECKING,
37+
Any,
38+
Iterable,
39+
List,
40+
Mapping,
41+
Match,
42+
Optional,
43+
Set,
44+
cast,
45+
)
46+
47+
48+
if TYPE_CHECKING:
49+
from importlib import metadata as _legacy
50+
from email.message import Message as _legacy_Metadata
51+
3752

3853
__all__ = [
3954
'Distribution',
@@ -959,7 +974,7 @@ def distributions(**kwargs) -> Iterable[Distribution | _legacy.Distribution]:
959974
return Distribution.discover(**kwargs)
960975

961976

962-
def metadata(distribution_name: str) -> _meta.PackageMetadata | email.message.Message:
977+
def metadata(distribution_name: str) -> _meta.PackageMetadata | _legacy_Metadata:
963978
"""Get the metadata for the named package.
964979
965980
:param distribution_name: The name of the distribution package to query.

0 commit comments

Comments
 (0)