Skip to content

Conversation

@srittau
Copy link
Collaborator

@srittau srittau commented Dec 19, 2025

Sequence and Mapping are commonly used in argument types. This can
be problematic, since they are not protocols, making it impossible to
safely duck type or mock them. Also, not all sequence- or mapping-like
types derive from these ABCs at runtime, although in typeshed we often
pretend they do. Ideally we'd be able to avoid this discrepancy in the
far future. Finally, the ABCs sometimes make more API promises than
their sub-classes fulfill. For example, Mapping arguments are
keyword-or-positional, while its most important subtype dict only
accepts positional arguments. These protocols have tighter guarantees.

SequenceLike contains most, MappingLike all methods from their
respective types, making them an easy substitute in argument types.

srittau and others added 2 commits December 19, 2025 18:35
`Sequence` and `Mapping` are commonly used in argument types. This can
be problematic, since they are not protocols, making it impossible to
safely duck type or mock them. Also, not all sequence- or mapping-like
types derive from these ABCs at runtime, although in typeshed we often
pretend they do. Ideally we'd be able to avoid this discrepancy in the
far future. Finally, the ABCs sometimes make more API promises than
their sub-classes fulfill. For example, `Mapping` arguments are
keyword-or-positional, while its most important subtype `dict` only
accepts positional arguments. These protocols have tighter guarantees.

`SequenceLike` contains most, `MappingLike` all methods from their
respective types, making them an easy substitute in argument types.
@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

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.

1 participant