Search code examples
pythontype-hinting

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?


Solution

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