Skip to content

Commit

Permalink
Use type check guard for legacy annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed May 2, 2024
1 parent 3bd2caa commit e3e8bbc
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,25 @@

from contextlib import suppress
from importlib import import_module
from importlib import metadata as _legacy
from importlib.abc import MetaPathFinder
from itertools import starmap
from typing import Any, Iterable, List, Mapping, Match, Optional, Set, cast
from typing import (
TYPE_CHECKING,
Any,
Iterable,
List,
Mapping,
Match,
Optional,
Set,
cast,
)


if TYPE_CHECKING:
from importlib import metadata as _legacy
from email.message import Message as _legacy_Metadata


__all__ = [
'Distribution',
Expand Down Expand Up @@ -981,7 +996,7 @@ def distributions(**kwargs) -> Iterable[Distribution | _legacy.Distribution]:
return Distribution.discover(**kwargs)


def metadata(distribution_name: str) -> _meta.PackageMetadata | email.message.Message:
def metadata(distribution_name: str) -> _meta.PackageMetadata | _legacy_Metadata:
"""Get the metadata for the named package.
:param distribution_name: The name of the distribution package to query.
Expand Down

0 comments on commit e3e8bbc

Please sign in to comment.