Skip to content

Commit 8189712

Browse files
committed
Fix pyright failure on Python 3.14
PackageMetadata (the protocol typing importlib.metadata.Distribution.metadata in 3.14) doesn't expose .get(), so pyright rejects the calls that parse Summary/Author/Maintainer. The runtime object (email.message.Message) still has .get(); bind it through an Any local so the calls pass type-checking. See #12925
1 parent 5721530 commit 8189712

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

  • extensions/positron-python/python_files/posit/positron

extensions/positron-python/python_files/posit/positron/ui.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import sys
1313
import webbrowser
1414
from pathlib import Path
15-
from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Union
15+
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
1616
from urllib.parse import urlparse
1717

1818
from comm.base_comm import BaseComm
@@ -127,12 +127,15 @@ def _get_packages_installed(_kernel: "PositronIPyKernel", _params: List[JsonData
127127
canonical = canonicalize_name(name)
128128
# Dedupe by canonical name - keeps first occurrence (the one that would be imported)
129129
if canonical not in packages_dict:
130-
summary = dist.metadata.get("Summary")
130+
# PackageMetadata (the 3.14 protocol) doesn't expose .get(), but the
131+
# runtime object (email.message.Message) always has it.
132+
metadata: Any = dist.metadata
133+
summary = metadata.get("Summary")
131134
# Fall back through Author → Author-email → Maintainer → Maintainer-email so
132135
# packages that set only a maintainer (e.g. click's `Pallets`) still show one.
133136
author = ""
134137
for field in ("Author", "Author-email", "Maintainer", "Maintainer-email"):
135-
value = dist.metadata.get(field)
138+
value = metadata.get(field)
136139
if value and value != "UNKNOWN":
137140
# Strip trailing email addresses in angle brackets to match the R side.
138141
stripped = re.sub(r"\s*<[^>]+>", "", value).strip()

0 commit comments

Comments
 (0)