Skip to content

multimethod does not recognize correctly 'collections.abc.Container' types #83

Answered by coady
Dvergatal asked this question in Q&A
Discussion options

You must be logged in to vote

It's actually working as intended; the catch is that strings are containers of strings.

>>> issubclass(str, Container)
True
>>> 't' in 'test'
True

You can try list[str] instead.

It's also worth mentioning that Container[] can't be fully supported, because there's no way to detect what it contains. Iterable[] or Collection[] checks the first element.

Replies: 8 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by coady
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Dvergatal
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #82 on February 03, 2023 04:22.