From 8c9cfafa314496a9821dd07bef8bdba84598f02a Mon Sep 17 00:00:00 2001 From: David Hotham Date: Fri, 7 Apr 2023 11:58:52 +0100 Subject: [PATCH] Handle importlib-metadata deprecation importlib-metadata promises that it will start raising KeyError for missing values, rather than returning None --- src/poetry/repositories/installed_repository.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/poetry/repositories/installed_repository.py b/src/poetry/repositories/installed_repository.py index 2a3496ac5ba..d8ff78c8455 100644 --- a/src/poetry/repositories/installed_repository.py +++ b/src/poetry/repositories/installed_repository.py @@ -257,9 +257,8 @@ def load(cls, env: Env, with_dependencies: bool = False) -> InstalledRepository: if path in skipped: continue - try: - name = canonicalize_name(distribution.metadata["name"]) - except TypeError: + name = distribution.metadata.get("name") # type: ignore[attr-defined] + if name is None: logger.warning( ( "Project environment contains an invalid distribution" @@ -271,6 +270,8 @@ def load(cls, env: Env, with_dependencies: bool = False) -> InstalledRepository: skipped.add(path) continue + name = canonicalize_name(name) + if name in seen: continue