Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which module should I use for Python collection type hints: collections.abc or typing?

I am unclear on whether to use typing or ABC classes for collection type hints in Python. It seems one can use either one, but the name typing suggests that's the preferred one. However, I see several places saying collections.abc should be used instead, not least PEP 585.

I am getting the sense that typing was created to support generics but that generics is being extended to the "regular" classes so typing is becoming obsolete. Is that the correct understanding?

like image 351
user118967 Avatar asked Oct 21 '25 05:10

user118967


1 Answers

Yes. collections.abc is the correct module going forward. Collections in typing have been deprecated since 3.9

like image 172
joel Avatar answered Oct 23 '25 21:10

joel