How to know what methods are supported by a type annotation?

Recently I was type annotating something. It turns out I was list[MyClass] as my type annotation because I wanted a Sequence that I could call .append() on. But at first I wasn’t sure if Sequence would work. By setting it as Sequence first, then trying to call .append() my type checker (pycharm’s inspections) told me that Sequence doesn’t support .append().

This is my usual workflow for figuring out if a certain type supports some method or attribute. But sometimes this is annoying and I wish there were a more direct way to get the answer. Is there a way to figure out ahead of time what methods a certain type supports? Or at least specifically for the Sequence type?

My apologies if some of my terminology is incorrect. Technical corrections would be appreciated.

Look at Sequence and MutableSequence.

1 Like

Thank you! That answers it for this one. I was on the collections documentation but didn’t get to the right page.

googling “python Sequence” got me to Built-in Types — Python 3.13.2 documentation.

googling “python collections” got me to collections — Container datatypes — Python 3.13.2 documentation but I guess I needed to go to the “next topic”: “collections.abc Abstract Base Classes for Containers”

edit: googling “python Sequence ABC” gets me to the right place.