Skip to content

Conversation

@randolf-scholz
Copy link
Contributor

@randolf-scholz randolf-scholz commented Jan 19, 2026

Fixes #14071

It doesn't seem like this will be fixed in CPython (python/cpython#135312), so we should at least fix this in the stubs to prevent false positives like this: mypy-playground

from collections.abc import Sequence

def null_count(seq: Sequence[int | None]) -> int:
    return seq.count(value=None)

null_count([1, None, 2])  # TypeError at runtime. (false negative)

Updated methods of the following types to only accept positional-only arguments:

  • Sequence
  • MutableSequence
  • AbstractSet
  • MutableSet
  • KeysView
  • ValuesView
  • ItemsView

2026-01-20 (@srittau): Marked as deferred, until tests for 3.9 are dropped (#13782).

- Sequence
- MutableSequence
- AbstractSet
- MutableSet
- KeysView
- ValuesView
- ItemsView
@randolf-scholz
Copy link
Contributor Author

I guess the failure for 3.9 will resolve itself soon: #13782

@github-actions
Copy link
Contributor

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

cwltool (https://github.com/common-workflow-language/cwltool)
+ cwltool/update.py: note: In function "v1_2to1_3dev1":
+ cwltool/update.py:55:25: error: Unexpected keyword argument "index" for "pop" of "MutableSequence"  [call-arg]
+ ...typeshed_to_test/stdlib/typing.pyi:695:5: note: "pop" of "MutableSequence" defined here

@srittau
Copy link
Collaborator

srittau commented Jan 20, 2026

LGTM, once we drop 3.9. (I've marked this as deferred until then.)

@srittau srittau added the status: deferred Issue or PR deferred until some precondition is fixed label Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: deferred Issue or PR deferred until some precondition is fixed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use positional only arguments for dunder methods in collections.abc

2 participants