Remove redundant inheritances from Iterator in builtins#12851
Remove redundant inheritances from Iterator in builtins#12851srittau merged 3 commits intopython:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
|
Three of the hits look like the ternary join issue again: Here's Spack: def anchorify(data: dict | list) -> None:
for key, value in data.items() if isinstance(data, dict) else enumerate(data):
passOptuna: def foo(values: list[str], names: list[str] | None):
iterator = enumerate(values) if names is None else zip(names, values)
for item in iterator:
passPySpark: from typing import Any
def drop(labels: Any):
if labels is not None:
return
foo = []
cols, labels = zip(*foo) if len(foo) > 0 else ([], [])
[label for label in labels]Ibis and psycopg show errors going away, and I think represent mypy inferring Any where it didn't before. The error from Ibis going away looks like this: from collections.abc import Iterable
class Value:
def cases(self, *branches: tuple[Value, Value]) -> Value: ...
def label(self, labels: Iterable[str]) -> Value:
return self.cases(*enumerate(labels))Take away the < tests/types/test_datetime.py:785: error: Argument 1 to "time" has incompatible type "*map[int]"; expected "tzinfo | None" [arg-type]
< tests/types/test_datetime.py:807: error: Argument 1 to "datetime" has incompatible type "*map[int]"; expected "tzinfo | None" [arg-type]Which comes from something like this: import datetime
def as_time(s):
datetime.time(*map(int, s.split(",")))
def as_naive_dt(s):
datetime.datetime(*map(int, s.split(",")))Following on from the revert and discussion of the related itertools MR (#12816 and #12853 ), I believe that all of these are blocking. I'll close out this MR in a day or two if nobody else has anything to say about it. |
|
Moving this to open since the revert of #12816 wasn't necessary. I'm pretty sure the three new messages in mypy-primer will go away for mypy 1.12. |
|
Let's update typeshed to latest mypy to confirm before merging this! |
|
Also this class of change probably makes type checkers slower, since structural checks are more expensive than nominal checks |
This comment has been minimized.
This comment has been minimized.
|
Diff from mypy_primer, showing the effect of this PR on open source code: psycopg (https://github.com/psycopg/psycopg)
+ tests/types/test_datetime.py:785: error: Unused "type: ignore" comment [unused-ignore]
+ tests/types/test_datetime.py:807: error: Unused "type: ignore" comment [unused-ignore]
ibis (https://github.com/ibis-project/ibis)
- ibis/expr/types/numeric.py:1223: error: Argument 1 to "cases" of "Value" has incompatible type "*enumerate[str]"; expected "tuple[Value, Value]" [arg-type]
|
This is the last batch of them; I saved the builtins for last.
previous: #12813 #12814 #12816 #12827
The unrelated extra newline in this MR was black's idea, not mine, to be clear.