Skip to content

Commit cdef0e0

Browse files
authored
🐛 fix(types): resolve ty 0.0.30 check failures (#571)
The scheduled `check` workflow on `main` started failing after `ty` 0.0.30 shifted its diagnostics on three unrelated call sites, blocking the green-main signal the project relies on. 🐛 None of the underlying code was buggy at runtime, but the type-check job treats any warning as fatal, so the job needs to be cleaned up before new work can merge cleanly. The dict feeding `_resolve_extras` in `PackageDAG.from_pkgs` now gets an explicit `dict[str, DistPackage]` annotation; without it `ty` infers `dict[NormalizedName, DistPackage]` from `canonicalize_name` and dict-key invariance turns the call into a type error, matching how `PackageDAG._index` is already annotated a few lines down. In the mermaid renderer, the `extra := context and context.build_node_extra_label(...)` pattern let `extra` widen to `RenderContext | str`; moving the walrus inside the right-hand side of the `and` narrows it back to `str` and mirrors the shape already used by the graphviz renderer. The `ty: ignore[invalid-argument-type]` directive on `sorted(map(str, specifier), ...)` no longer corresponds to a real diagnostic in 0.0.30 and was being flagged as unused, so it is dropped while keeping the adjacent comment that explains the `reverse=True` argument. No runtime behaviour changes. ✅
1 parent 5a898d7 commit cdef0e0

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/pipdeptree/_models/dag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def from_pkgs(
5858
) -> PackageDAG:
5959
warning_printer = get_warning_printer()
6060
dist_pkgs = [DistPackage(p) for p in pkgs]
61-
idx = {p.key: p for p in dist_pkgs}
61+
idx: dict[str, DistPackage] = {p.key: p for p in dist_pkgs}
6262
pkg_deps: dict[DistPackage, list[ReqPackage]] = {}
6363
dist_name_to_invalid_reqs_dict: dict[str, list[str]] = {}
6464
for pkg in dist_pkgs:

src/pipdeptree/_models/package.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def render_as_branch(self, *, frozen: bool) -> str:
254254

255255
@property
256256
def version_spec(self) -> str | None:
257-
specs = sorted(map(str, self._obj.specifier), reverse=True) # ty: ignore[invalid-argument-type] # `reverse` makes '>' prior to '<'
257+
specs = sorted(map(str, self._obj.specifier), reverse=True) # `reverse` makes '>' prior to '<'
258258
return ",".join(specs) if specs else None
259259

260260
@property

src/pipdeptree/_render/mermaid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _build_reversed_mermaid(
7878
package.project_name,
7979
"(missing)" if package.is_missing else package.installed_version,
8080
]
81-
if extra := context and context.build_node_extra_label(package.key, tree, "<br/>"):
81+
if context and (extra := context.build_node_extra_label(package.key, tree, "<br/>")):
8282
label_parts.append(extra)
8383
package_key = _mermaid_id(package.key, node_ids_map)
8484
nodes.add(f'{package_key}["{"<br/>".join(label_parts)}"]')
@@ -97,7 +97,7 @@ def _build_forward_mermaid(
9797
) -> None:
9898
for package, dependencies in tree.items():
9999
label_parts = [package.project_name, package.version]
100-
if extra := context and context.build_node_extra_label(package.key, tree, "<br/>"):
100+
if context and (extra := context.build_node_extra_label(package.key, tree, "<br/>")):
101101
label_parts.append(extra)
102102
package_key = _mermaid_id(package.key, node_ids_map)
103103
nodes.add(f'{package_key}["{"<br/>".join(label_parts)}"]')

0 commit comments

Comments
 (0)