Solution 1:

First choice is don't use builtin names for custom objects. If that's not possible, disambiguate with

import builtins

builtins.list[str]

or ClassName.list as appropriate

Solution 2:

Well, list is a built-in in Python, and it's good practice not to override it, for this very reason. Your new list function overrides the existing one, and you won't be able to access the original function in the same file.

I would usually recommend you renaming your function to something else. However, this doesn't seem possible in your case.

Another option you can consider is importing the List type

from typing import List


def foobar(foo: List[str], bar: List[int]) -> bool:
    ...

A bit inconvenient, but it gets around your specific problem + it works the same way.

Edit: If you can't import List, you can make a type alias

listAlias = list


class MyClass:
    def list(self):
        ...

    def foobar(self, foo: listAlias[str], bar: listAlias[int]) -> bool:
        ...

Or you can import the builtins module like in Joel's answer