Skip to content

Conversation

@tungol
Copy link
Contributor

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.

@github-actions

This comment has been minimized.

@tungoltungol marked this pull request as draft October 18, 2024 16:50
@tungol
Copy link
ContributorAuthor

Three of the hits look like the ternary join issue again:

Here's Spack:

defanchorify(data: dict|list) ->None: forkey, valueindata.items() ifisinstance(data, dict) elseenumerate(data): pass

Optuna:

deffoo(values: list[str], names: list[str] |None): iterator=enumerate(values) ifnamesisNoneelsezip(names, values) foriteminiterator: pass

PySpark:

fromtypingimportAnydefdrop(labels: Any): iflabelsisnotNone: returnfoo= [] cols, labels=zip(*foo) iflen(foo) >0else ([], []) [labelforlabelinlabels]

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:

fromcollections.abcimportIterableclassValue: defcases(self, *branches: tuple[Value, Value]) ->Value: ... deflabel(self, labels: Iterable[str]) ->Value: returnself.cases(*enumerate(labels))

Take away the type: ignore from psycopg and the diff is:

< 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:

importdatetimedefas_time(s): datetime.time(*map(int, s.split(","))) defas_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.

@tungol
Copy link
ContributorAuthor

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.

@hauntsaninja
Copy link
Collaborator

Let's update typeshed to latest mypy to confirm before merging this!

@hauntsaninja
Copy link
Collaborator

Also this class of change probably makes type checkers slower, since structural checks are more expensive than nominal checks

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

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]

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@tungol@hauntsaninja@srittau@AlexWaygood