Skip to content
Discussion options

You must be logged in to vote

It depends on the Python version, if you're still on 3.8 you will need to add some if TYPE_CHECKING blocks to deal with the fact that ABCMeta (or rather collections.abc.MutableSequence, which collections.UserList inherits from) is not subscriptable.

Starting with 3.9 it should be as simple as:

import collections

class TestClass(collections.UserList[str]):
    def __init__(self) -> None:
        super().__init__()

    def lower_all(self) -> None:
        for count, s in enumerate(self.data):
            self.data[count] = s.lower()

With 3.8 you would need to do something like the following:

import collections
from typing import TYPE_CHECKING
if TYPE_CHECKING:
    BaseList = collections.U…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@JakobDev
Comment options

@Daverball
Comment options

@JakobDev
Comment options

Answer selected by JakobDev
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