Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this error mean: "TypeError: Parameters to generic types must be types"?

I'm not sure what this error means:

TypeError: Parameters to generic types must be types. Got slice(typing.List, <class 'int'>, None).

I am trying to confirm if a matrix has a given cell/index in it. (In matrix [[A, B, C], [D, E, F]] does cell/index [0, 2] exist? Yes at C).

My input parameter is a list specifying the cell's index. I want to take the cell/list and modify it to check if it exists. Every time I try to touch the parameter list, it gives the error.

def in_matrix(matr: List[List:int], cell: List[int]) -> bool:
    b = cell.pop()
    a = cell.pop()
    print(a)
    print(b)
    for y in range(len(matr)):
        for x in range(len(matr[y])):
            if matr[a][b] == True:
                return True
            else:
                return False
like image 951
user12349182 Avatar asked Nov 10 '19 18:11

user12349182


People also ask

What is generic type in Python?

Generic types have one or more type parameters, which can be arbitrary types. For example, dict[int, str] has the type parameters int and str , and list[int] has a type parameter int .

What is generic type?

A generic type is a generic class or interface that is parameterized over types. The following Box class will be modified to demonstrate the concept.

What is generic type arguments?

The generic argument list is a comma-separated list of type arguments. A type argument is the name of an actual concrete type that replaces a corresponding type parameter in the generic parameter clause of a generic type. The result is a specialized version of that generic type.

Is generic type parameter?

Generic MethodsA type parameter, also known as a type variable, is an identifier that specifies a generic type name. The type parameters can be used to declare the return type and act as placeholders for the types of the arguments passed to the generic method, which are known as actual type arguments.


1 Answers

This type matr: List[List:int] should be matr: List[List[int]] (in Python >= 3.9 you can even just use matr: list[list[int]]).

This means that matr is a list of integer lists, like:

matr = [[1, 2, 3],
        [4, 5, 6],
        [7, 8, 9]]
like image 191
ruohola Avatar answered Oct 19 '22 04:10

ruohola