Skip to content

Fix heapq and _heapq stubs#15669

Merged
srittau merged 9 commits into
python:mainfrom
jonathandung:patch-1
May 18, 2026
Merged

Fix heapq and _heapq stubs#15669
srittau merged 9 commits into
python:mainfrom
jonathandung:patch-1

Conversation

@jonathandung
Copy link
Copy Markdown
Contributor

@jonathandung jonathandung commented Apr 23, 2026

Closes #15668.

@github-actions

This comment has been minimized.

Comment thread stdlib/_heapq.pyi Outdated
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Comment thread stdlib/_heapq.pyi Outdated
@github-actions

This comment has been minimized.

@JelleZijlstra
Copy link
Copy Markdown
Member

The new pyspark errors in the mypy-primer output are unfortunate. Can we avoid them?

@jonathandung
Copy link
Copy Markdown
Contributor Author

They appear to be fixable by introducing a new type variable, but I don't know if it's worth the trouble to open an issue over there.

@github-actions
Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

spark (https://github.com/apache/spark)
+ python/pyspark/shuffle.py:556: error: Argument "key" to "merge" has incompatible type "Callable[[V], Any] | None"; expected "Callable[[V], SupportsDunderLT[Any] | SupportsDunderGT[Any]]"  [arg-type]
+ python/pyspark/core/rdd.py:2575: error: Argument "key" to "nlargest" has incompatible type "Callable[[T], S] | None"; expected "Callable[[T], SupportsDunderLT[Any] | SupportsDunderGT[Any]]"  [arg-type]
+ python/pyspark/core/rdd.py:2578: error: Argument "key" to "nlargest" has incompatible type "Callable[[T], S] | None"; expected "Callable[[T], SupportsDunderLT[Any] | SupportsDunderGT[Any]]"  [arg-type]
+ python/pyspark/core/rdd.py:2635: error: Argument 3 to "nsmallest" has incompatible type "Callable[[T], S] | None"; expected "Callable[[T], SupportsDunderLT[Any] | SupportsDunderGT[Any]]"  [arg-type]
+ python/pyspark/core/rdd.py:2637: error: Argument 3 to "nsmallest" has incompatible type "Callable[[T], S] | None"; expected "Callable[[T], SupportsDunderLT[Any] | SupportsDunderGT[Any]]"  [arg-type]

Copy link
Copy Markdown
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pyspark's current annotations are unsound the same way our annotations were unsound before this PR. I'm fine with the new primer errors, although I'd like @JelleZijlstra's opinion.

@JelleZijlstra
Copy link
Copy Markdown
Member

All right, feel free to go ahead.

@srittau srittau merged commit ee21208 into python:main May 18, 2026
58 checks passed
Sign up for free to 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.

heapq.merge, heapq.nlargest and heapq.nsmallest are typed inadequately

3 participants