Repository navigation
Allow arbitrary types in dict.pop (2 overloads) - #15296
randolf-scholz wants to merge 7 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
|
Diff from mypy_primer, showing the effect of this PR on open source code: |
dict.pop (2 overloads)
|
It seems the 3-overload variant hides some dubious code: take the class Copy(PreImage):
def __init__(self, rd: RepositoryDetails, path: Path, config: dict[str, Any]):
super().__init__(rd, path)
self.source = config.pop("source", None)
if self.source is None:
raise ValueError("mzbuild config is missing 'source' argument")
self.destination = config.pop("destination", None)
if self.destination is None:
raise ValueError("mzbuild config is missing 'destination' argument")
self.matching = config.pop("matching", "*")
def run(self, prep: Any) -> None:
super().run(prep)
for src in self.inputs():
dst = self.path / self.destination / src
dst.parent.mkdir(parents=True, exist_ok=True)
shutil.copy(self.rd.root / self.source / src, dst)This should probably be written something like this instead: if (dest := config.pop("destination", None)) is None:
raise ValueError("mzbuild config is missing 'destination' argument")
else:
assert isinstance(dest, str | Path)
self.destination = dest |
|
Another dubious case: master reports no error here, which seems like a sure false negative. This should be rewritten as |
|
|
| @overload | ||
| def pop(self, key: _KT, default: _VT, /) -> _VT: ... |
There was a problem hiding this comment.
We should separate removing this overload from changing _KT to object to better see what the issues are, and because those unrelated changes should not be part of the same PR.
There was a problem hiding this comment.
#15297 is the same PR, keeping the overload. Should I reopen it?
|
Residual diff compared to #15297 |
Fixes #15271
new overloads:
Note: I remove the redundant looking overload. was this necessary for some mypy quirk? It doesn't seem to make any difference without context: https://mypy-play.net/?mypy=latest&python=3.12&gist=1db2e079cf94bb56b590ea1f385259fd