Skip to content

Commit 3f9fd76

Browse files
Robert Denhamclaude
andcommitted
Use 'in' narrowing instead of .get() for TypedDict uid/puid lookup
Pyright can narrow NotRequired TypedDict fields via 'in' checks, removing the need for type: ignore. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7c6473f commit 3f9fd76

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

filesender/api.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,11 @@ def iter_files(paths: Iterable[Path], root: Optional[Path] = None) -> Iterable[T
100100
yield str(path.relative_to(root)), path
101101

102102
def _file_key(file_info: response.File) -> str:
103-
key = file_info.get("uid") or file_info.get("puid") # type: ignore[typeddict-item]
104-
if key is None:
105-
raise Exception(f"File response for {file_info['name']!r} has neither 'uid' nor 'puid' field")
106-
return key
103+
if "uid" in file_info:
104+
return file_info["uid"]
105+
if "puid" in file_info:
106+
return file_info["puid"]
107+
raise Exception(f"File response for {file_info['name']!r} has neither 'uid' nor 'puid' field")
107108

108109
class EndpointHandler:
109110
base: str

0 commit comments

Comments
 (0)