Skip to content

Commit e3e8bbc

Browse files
committed
Use type check guard for legacy annotations
1 parent 3bd2caa commit e3e8bbc

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
@@ -31,10 +31,25 @@
3131

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

3954
__all__ = [
4055
'Distribution',
@@ -981,7 +996,7 @@ def distributions(**kwargs) -> Iterable[Distribution | _legacy.Distribution]:
981996
return Distribution.discover(**kwargs)
982997

983998

984-
def metadata(distribution_name: str) -> _meta.PackageMetadata | email.message.Message:
999+
def metadata(distribution_name: str) -> _meta.PackageMetadata | _legacy_Metadata:
9851000
"""Get the metadata for the named package.
9861001
9871002
:param distribution_name: The name of the distribution package to query.

0 commit comments

Comments
 (0)