Skip to content

Commit 170b2c1

Browse files
committed
Use strict optional checking in legacy resolver
The assert in _set_req_to_reinstall is definitely correct, the three call sites have guards The assert in _populate_link is a little trickier. It's not obvious to me how to prove it will never trigger. Note that if link were ever None, it could potentially cause AttributeError in Cache._get_cache_path_parts and direct_url_from_link The assert in _resolve_one is safe, if req_to_install.name was None it would raise TypeError in canonicalize_name I can't prove that req.name is not None in get_installation_order and the code would work fine if that were the case (since it's a defaultdict), so I opted to just ignore
1 parent eddd9dd commit 170b2c1

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

news/4CCE4788-B8B3-402E-9A88-2981AD074999.trivial.rst

Whitespace-only changes.

src/pip/_internal/resolution/legacy/resolver.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"""
1212

1313
# The following comment should be removed at some point in the future.
14-
# mypy: strict-optional=False
1514

1615
import logging
1716
import sys
@@ -325,6 +324,7 @@ def _set_req_to_reinstall(self, req: InstallRequirement) -> None:
325324
"""
326325
# Don't uninstall the conflict if doing a user install and the
327326
# conflict is not a user install.
327+
assert req.satisfied_by is not None
328328
if not self.use_user_site or req.satisfied_by.in_usersite:
329329
req.should_reinstall = True
330330
req.satisfied_by = None
@@ -423,6 +423,8 @@ def _populate_link(self, req: InstallRequirement) -> None:
423423

424424
if self.wheel_cache is None or self.preparer.require_hashes:
425425
return
426+
427+
assert req.link is not None, "_find_requirement_link unexpectedly returned None"
426428
cache_entry = self.wheel_cache.get_cache_entry(
427429
link=req.link,
428430
package_name=req.name,
@@ -536,6 +538,7 @@ def add_req(subreq: Requirement, extras_requested: Iterable[str]) -> None:
536538
with indent_log():
537539
# We add req_to_install before its dependencies, so that we
538540
# can refer to it when adding dependencies.
541+
assert req_to_install.name is not None
539542
if not requirement_set.has_requirement(req_to_install.name):
540543
# 'unnamed' requirements will get added here
541544
# 'unnamed' requirements can only come from being directly
@@ -591,7 +594,7 @@ def schedule(req: InstallRequirement) -> None:
591594
if req.constraint:
592595
return
593596
ordered_reqs.add(req)
594-
for dep in self._discovered_dependencies[req.name]:
597+
for dep in self._discovered_dependencies[req.name]: # type: ignore[index]
595598
schedule(dep)
596599
order.append(req)
597600

0 commit comments

Comments
 (0)